MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
bucket.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <mongocxx/v1/gridfs/bucket-fwd.hpp> // IWYU pragma: export
18
19//
20
22
25
34
37
41
42#include <cstddef>
43#include <cstdint>
44#include <istream>
45#include <ostream>
46#include <string>
47#include <system_error>
48#include <type_traits>
49
50namespace mongocxx {
51namespace v1 {
52namespace gridfs {
53
62class bucket {
63 private:
64 class impl;
65 void* _impl;
66
67 public:
68 class options;
69
76
84
91 MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket&& other) noexcept;
92
97
101 MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket const& other);
102
110
114 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const;
115
121 bsoncxx::v1::stdx::string_view filename,
122 v1::gridfs::upload_options const& opts = {});
123
125 v1::client_session const& session,
127 v1::gridfs::upload_options const& opts = {});
130
145 v1::gridfs::upload_options const& opts = {});
146
148 v1::client_session const& session,
151 v1::gridfs::upload_options const& opts = {});
154
161 std::istream& input,
162 v1::gridfs::upload_options const& opts = {});
163
165 v1::client_session const& session,
167 std::istream& input,
168 v1::gridfs::upload_options const& opts = {});
171
183 std::istream& input,
184 v1::gridfs::upload_options const& opts = {});
185
187 v1::client_session const& session,
190 std::istream& input,
191 v1::gridfs::upload_options const& opts = {});
194
207
209 v1::client_session const& session,
213
227
229 download_to_stream(v1::client_session const& session, bsoncxx::v1::types::view id, std::ostream& output);
232
248 download_to_stream(bsoncxx::v1::types::view id, std::ostream& output, std::size_t start, std::size_t end);
249
251 v1::client_session const& session,
252 bsoncxx::v1::types::view id,
253 std::ostream& output,
254 std::size_t start,
255 std::size_t end);
258
269
270 MONGOCXX_ABI_EXPORT_CDECL(void) delete_file(v1::client_session const& session, bsoncxx::v1::types::view id);
273
281 MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) find(bsoncxx::v1::document::view filter, v1::find_options const& opts = {});
282
284 find(v1::client_session const& session, bsoncxx::v1::document::view filter, v1::find_options const& opts = {});
287
292
306
312 static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
313
319 friend std::error_code make_error_code(errc v) {
320 return {static_cast<int>(v), error_category()};
321 }
322
323 class internal;
324
325 private:
326 /* explicit(false) */ bucket(void* impl);
327};
328
346 private:
347 class impl;
348 void* _impl;
349
350 public:
357
365
372 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept;
373
378
382 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other);
383
391
396
400 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) bucket_name() const;
401
406
410 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) chunk_size_bytes() const;
411
416
421
426
431
436
441
442 class internal;
443
444 private:
445 /* explicit(false) */ options(void* impl);
446};
447
448} // namespace gridfs
449} // namespace v1
450} // namespace mongocxx
451
452namespace std {
453
454template <>
455struct is_error_code_enum<mongocxx::v1::gridfs::bucket::errc> : true_type {};
456
457} // namespace std
458
460
A polyfill for std::string_view.
Definition string_view.hpp:412
A non-owning, read-only union of BSON type values.
Definition view.hpp:1023
A MongoDB client session.
Definition client_session.hpp:48
A MongoDB cursor.
Definition cursor.hpp:41
Options for a "find" command.
Definition find_options.hpp:72
Options for mongocxx::v1::gridfs::bucket.
Definition bucket.hpp:345
options & read_concern(v1::read_concern v)
Set the "readConcern" field.
options(options &&other) noexcept
Move constructor.
options & chunk_size_bytes(std::int32_t v)
Set the "chunkSizeBytes" field.
options & bucket_name(std::string v)
Set the "bucketName" field.
options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
options & read_preference(v1::read_preference v)
Set the "readPreference" field.
~bucket()
Destroy this object.
errc
Errors codes which may be returned by mongocxx::v1::gridfs::bucket.
Definition bucket.hpp:298
@ not_found
The requested GridFS file does not exist.
Definition bucket.hpp:302
@ invalid_bucket_name
The "bucketName" field must not be empty.
Definition bucket.hpp:300
@ corrupt_data
The GridFS file is in an invalid or inconsistent state.
Definition bucket.hpp:303
@ zero
Zero.
Definition bucket.hpp:299
@ invalid_byte_range
[start, end) must be a valid range of byte indexes within the requested GridFS file.
Definition bucket.hpp:304
@ invalid_chunk_size_bytes
The "chunkSizeBytes" field must be a positive value.
Definition bucket.hpp:301
v1::cursor find(bsoncxx::v1::document::view filter, v1::find_options const &opts={})
Find files within this bucket matching the given query filter.
bsoncxx::v1::stdx::string_view bucket_name() const
Return the name of this bucket.
v1::gridfs::downloader open_download_stream(bsoncxx::v1::types::view id)
Return a downloader for the requested file from this bucket.
v1::gridfs::uploader open_upload_stream_with_id(v1::client_session const &session, bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
Return an uploader for a new file to this bucket.
bucket(bucket &&other) noexcept
Move constructor.
v1::gridfs::upload_result upload_from_stream(bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
Equivalent to upload_from_stream_with_id with a file ID generated using bsoncxx::v1::oid.
v1::gridfs::downloader open_download_stream(v1::client_session const &session, bsoncxx::v1::types::view id)
Return a downloader for the requested file from this bucket.
void upload_from_stream_with_id(v1::client_session const &session, bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
Upload the contents of input as a new file to this bucket.
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition bucket.hpp:319
v1::gridfs::uploader open_upload_stream(v1::client_session const &session, bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
Equivalent to open_upload_stream_with_id with a file ID generated using bsoncxx::v1::oid.
void delete_file(bsoncxx::v1::types::view id)
Delete the requested file from this bucket.
v1::gridfs::uploader open_upload_stream(bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
Equivalent to open_upload_stream_with_id with a file ID generated using bsoncxx::v1::oid.
void download_to_stream(bsoncxx::v1::types::view id, std::ostream &output)
Download the entire contents of the requested file from this bucket into output.
v1::gridfs::uploader open_upload_stream_with_id(bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
Return an uploader for a new file to this bucket.
bucket()
Default initialization.
void upload_from_stream_with_id(bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
Upload the contents of input as a new file to this bucket.
v1::gridfs::upload_result upload_from_stream(v1::client_session const &session, bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
Equivalent to upload_from_stream_with_id with a file ID generated using bsoncxx::v1::oid.
static std::error_category const & error_category()
The error category for mongocxx::v1::gridfs::bucket::errc.
Support for downloading files from a GridFS bucket.
Definition downloader.hpp:44
Options related to uploading a file to a GridFS bucket.
Definition upload_options.hpp:48
Result of uploading a file to a GridFS bucket.
Definition upload_result.hpp:42
Support for uploading files to a GridFS bucket.
Definition uploader.hpp:44
Provides mongocxx::v1::find_options.
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard postlude header.
The mongocxx v1 macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities related to GridFS.
Declares entities whose ABI stability is guaranteed for documented symbols.
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v1::gridfs::upload_options.
Declares mongocxx::v1::gridfs::upload_result.
Declares mongocxx::v1::client_session.
Declares mongocxx::v1::cursor.
Declares bsoncxx::v1::document::view.
Declares mongocxx::v1::gridfs::bucket.
Declares mongocxx::v1::gridfs::downloader.
Declares mongocxx::v1::gridfs::uploader.
Declares mongocxx::v1::read_concern.
Declares mongocxx::v1::read_preference.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Declares non-owning, read-only entities representing a BSON type value.
Declares mongocxx::v1::write_concern.