MongoDB C++ Driver mongocxx-3.11.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 <istream>
18#include <memory>
19#include <ostream>
20
23
28
29#include <mongocxx/cursor.hpp>
36#include <mongocxx/stdx.hpp>
37
39
40namespace mongocxx {
41namespace v_noabi {
42namespace gridfs {
43
67class bucket {
68 public:
75
80
84 MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket&&) noexcept;
85
90
95
100
104 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
105
133 open_upload_stream(stdx::string_view filename, const options::gridfs::upload& options = {});
134
167 stdx::string_view filename,
168 const options::gridfs::upload& options = {});
169
199 open_upload_stream_with_id(bsoncxx::v_noabi::types::bson_value::view id,
200 stdx::string_view filename,
201 const options::gridfs::upload& options = {});
202
237 bsoncxx::v_noabi::types::bson_value::view id,
238 stdx::string_view filename,
239 const options::gridfs::upload& options = {});
240
283 upload_from_stream(stdx::string_view filename,
284 std::istream* source,
285 const options::gridfs::upload& options = {});
286
333 stdx::string_view filename,
334 std::istream* source,
335 const options::gridfs::upload& options = {});
336
379 upload_from_stream_with_id(bsoncxx::v_noabi::types::bson_value::view id,
380 stdx::string_view filename,
381 std::istream* source,
382 const options::gridfs::upload& options = {});
383
430 bsoncxx::v_noabi::types::bson_value::view id,
431 stdx::string_view filename,
432 std::istream* source,
433 const options::gridfs::upload& options = {});
434
451 open_download_stream(bsoncxx::v_noabi::types::bson_value::view id);
452
474 bsoncxx::v_noabi::types::bson_value::view id);
475
497 download_to_stream(bsoncxx::v_noabi::types::bson_value::view id, std::ostream* destination);
498
506 download_to_stream(bsoncxx::v_noabi::types::bson_value::view id,
507 std::ostream* destination,
508 std::size_t start,
509 std::size_t end);
510
536 bsoncxx::v_noabi::types::bson_value::view id,
537 std::ostream* destination);
538
547 bsoncxx::v_noabi::types::bson_value::view id,
548 std::ostream* destination,
549 std::size_t start,
550 std::size_t end);
551
563 MONGOCXX_ABI_EXPORT_CDECL(void) delete_file(bsoncxx::v_noabi::types::bson_value::view id);
564
580 delete_file(const client_session& session, bsoncxx::v_noabi::types::bson_value::view id);
581
602 find(bsoncxx::v_noabi::document::view_or_value filter, const options::find& options = {});
603
628 find(const client_session& session,
629 bsoncxx::v_noabi::document::view_or_value filter,
630 const options::find& options = {});
631
639
640 private:
641 friend ::mongocxx::v_noabi::database;
642
643 // Constructs a new GridFS bucket. Throws if options are invalid.
644 bucket(const database& db, const options::gridfs::bucket& options);
645
646 void create_indexes_if_nonexistent(const client_session* session);
647
648 uploader _open_upload_stream_with_id(const client_session* session,
650 stdx::string_view filename,
651 const options::gridfs::upload& options);
652
653 void _upload_from_stream_with_id(const client_session* session,
655 stdx::string_view filename,
656 std::istream* source,
657 const options::gridfs::upload& options);
658
659 downloader _open_download_stream(const client_session* session,
663
664 void _download_to_stream(const client_session* session,
666 std::ostream* destination,
669
670 void _delete_file(const client_session* session, bsoncxx::v_noabi::types::bson_value::view id);
671
672 class impl;
673
674 impl& _get_impl();
675 const impl& _get_impl() const;
676
677 std::unique_ptr<impl> _impl;
678};
679
680} // namespace gridfs
681} // namespace v_noabi
682} // namespace mongocxx
683
685
A polyfill for std::optional<T>.
Definition optional.hpp:874
A polyfill for std::string_view.
Definition string_view.hpp:503
A view-only variant that can contain any BSON type.
Definition view.hpp:41
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:48
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:42
Class representing a MongoDB database.
Definition database.hpp:47
Class representing a GridFS bucket.
Definition bucket.hpp:67
uploader open_upload_stream_with_id(bsoncxx::v_noabi::types::bson_value::view id, stdx::string_view filename, const options::gridfs::upload &options={})
Opens a gridfs::uploader to create a new GridFS file.
downloader open_download_stream(bsoncxx::v_noabi::types::bson_value::view id)
Opens a gridfs::downloader to read a GridFS file.
stdx::string_view bucket_name() const
Gets the name of the GridFS bucket.
void delete_file(bsoncxx::v_noabi::types::bson_value::view id)
Deletes a GridFS file from the bucket.
bucket() noexcept
Default constructs a bucket object. The bucket is equivalent to the state of a moved from bucket....
void upload_from_stream_with_id(bsoncxx::v_noabi::types::bson_value::view id, stdx::string_view filename, std::istream *source, const options::gridfs::upload &options={})
Creates a new GridFS file with a user-supplied unique id by uploading bytes from an input stream.
void download_to_stream(bsoncxx::v_noabi::types::bson_value::view id, std::ostream *destination)
Downloads the contents of a stored GridFS file from the bucket and writes it to a stream.
cursor find(bsoncxx::v_noabi::document::view_or_value filter, const options::find &options={})
Finds the documents in the files collection of the bucket which match the provided filter.
uploader open_upload_stream(stdx::string_view filename, const options::gridfs::upload &options={})
Opens a gridfs::uploader to create a new GridFS file. The id of the file will be automatically genera...
result::gridfs::upload upload_from_stream(stdx::string_view filename, std::istream *source, const options::gridfs::upload &options={})
Creates a new GridFS file by uploading bytes from an input stream. The id of the file will be automat...
Class used to download a GridFS file.
Definition downloader.hpp:49
Class used to upload a GridFS file.
Definition uploader.hpp:44
Class representing the optional arguments to a MongoDB GridFS bucket creation operation.
Definition bucket.hpp:38
Class representing the optional arguments to a MongoDB GridFS upload operation.
Definition upload.hpp:34
Class representing the result of a GridFS upload operation.
Definition upload.hpp:30
Provides mongocxx::v_noabi::cursor.
Declares mongocxx::v_noabi::database.
Provides bsoncxx::v_noabi::document::view_or_value.
Provides utilities to download GridFS files.
Provides mongocxx::v_noabi::options::find.
Declares mongocxx::v_noabi::gridfs::bucket.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:222
The mongocxx macro guard postlude header.
The mongocxx macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace within which all mongocxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::options::gridfs::bucket.
Provides mongocxx::v_noabi::options::gridfs::upload.
Provides mongocxx::v_noabi::result::gridfs::upload.
Redeclares bsoncxx::v_noabi::stdx in mongocxx::v_noabi::stdx for internal use.
Provides std::string_view-related polyfills for library API usage.
Provides bsoncxx::v_noabi::types::bson_value::view.
Provides utilities to upload GridFS files.