MongoDB C++ Driver 4.4.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
60class bucket {
61 private:
62 class impl;
63 void* _impl;
64
65 public:
66 class options;
67
74
82
89 MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket&& other) noexcept;
90
95
99 MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket const& other);
100
108
112 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const;
113
119 bsoncxx::v1::stdx::string_view filename,
120 v1::gridfs::upload_options const& opts = {});
121
123 v1::client_session const& session,
125 v1::gridfs::upload_options const& opts = {});
128
143 v1::gridfs::upload_options const& opts = {});
144
146 v1::client_session const& session,
149 v1::gridfs::upload_options const& opts = {});
152
159 std::istream& input,
160 v1::gridfs::upload_options const& opts = {});
161
163 v1::client_session const& session,
165 std::istream& input,
166 v1::gridfs::upload_options const& opts = {});
169
181 std::istream& input,
182 v1::gridfs::upload_options const& opts = {});
183
185 v1::client_session const& session,
188 std::istream& input,
189 v1::gridfs::upload_options const& opts = {});
192
205
207 v1::client_session const& session,
211
225
227 download_to_stream(v1::client_session const& session, bsoncxx::v1::types::view id, std::ostream& output);
230
246 download_to_stream(bsoncxx::v1::types::view id, std::ostream& output, std::size_t start, std::size_t end);
247
249 v1::client_session const& session,
250 bsoncxx::v1::types::view id,
251 std::ostream& output,
252 std::size_t start,
253 std::size_t end);
256
267
268 MONGOCXX_ABI_EXPORT_CDECL(void) delete_file(v1::client_session const& session, bsoncxx::v1::types::view id);
271
279 MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) find(bsoncxx::v1::document::view filter, v1::find_options const& opts = {});
280
282 find(v1::client_session const& session, bsoncxx::v1::document::view filter, v1::find_options const& opts = {});
285
290
302
306 static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
307
311 friend std::error_code make_error_code(errc v) {
312 return {static_cast<int>(v), error_category()};
313 }
314
315 class internal;
316
317 private:
318 /* explicit(false) */ bucket(void* impl);
319};
320
336 private:
337 class impl;
338 void* _impl;
339
340 public:
347
355
362 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept;
363
368
372 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other);
373
381
386
390 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) bucket_name() const;
391
396
400 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) chunk_size_bytes() const;
401
406
411
416
421
426
431
432 class internal;
433
434 private:
435 /* explicit(false) */ options(void* impl);
436};
437
438} // namespace gridfs
439} // namespace v1
440} // namespace mongocxx
441
442namespace std {
443
444template <>
445struct is_error_code_enum<mongocxx::v1::gridfs::bucket::errc> : true_type {};
446
447} // namespace std
448
450
A polyfill for std::string_view.
Definition string_view.hpp:412
A non-owning, read-only union of BSON type values.
Definition view.hpp:979
A MongoDB client session.
Definition client_session.hpp:46
A MongoDB cursor.
Definition cursor.hpp:39
Options for a "find" command.
Definition find_options.hpp:72
Options for mongocxx::v1::gridfs::bucket.
Definition bucket.hpp:335
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:294
@ not_found
The requested GridFS file does not exist.
Definition bucket.hpp:298
@ invalid_bucket_name
The "bucketName" field must not be empty.
Definition bucket.hpp:296
@ corrupt_data
The GridFS file is in an invalid or inconsistent state.
Definition bucket.hpp:299
@ zero
Zero.
Definition bucket.hpp:295
@ invalid_byte_range
[start, end) must be a valid range of byte indexes within the requested GridFS file.
Definition bucket.hpp:300
@ invalid_chunk_size_bytes
The "chunkSizeBytes" field must be a positive value.
Definition bucket.hpp:297
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:311
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:42
Options related to uploading a file to a GridFS bucket.
Definition upload_options.hpp:46
Result of uploading a file to a GridFS bucket.
Definition upload_result.hpp:40
Support for uploading files to a GridFS bucket.
Definition uploader.hpp:42
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.