MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
38
39namespace mongocxx {
40namespace v_noabi {
41namespace gridfs {
42
66class bucket {
67 public:
74
79
83 MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket&&) noexcept;
84
89
94
99
103 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
104
132 open_upload_stream(bsoncxx::v_noabi::stdx::string_view filename, options::gridfs::upload const& options = {});
133
166 client_session const& session,
167 bsoncxx::v_noabi::stdx::string_view filename,
168 options::gridfs::upload const& options = {});
169
200 bsoncxx::v_noabi::types::bson_value::view id,
201 bsoncxx::v_noabi::stdx::string_view filename,
202 options::gridfs::upload const& options = {});
203
238 client_session const& session,
239 bsoncxx::v_noabi::types::bson_value::view id,
240 bsoncxx::v_noabi::stdx::string_view filename,
241 options::gridfs::upload const& options = {});
242
286 bsoncxx::v_noabi::stdx::string_view filename,
287 std::istream* source,
288 options::gridfs::upload const& options = {});
289
336 client_session const& session,
337 bsoncxx::v_noabi::stdx::string_view filename,
338 std::istream* source,
339 options::gridfs::upload const& options = {});
340
384 bsoncxx::v_noabi::types::bson_value::view id,
385 bsoncxx::v_noabi::stdx::string_view filename,
386 std::istream* source,
387 options::gridfs::upload const& options = {});
388
435 client_session const& session,
436 bsoncxx::v_noabi::types::bson_value::view id,
437 bsoncxx::v_noabi::stdx::string_view filename,
438 std::istream* source,
439 options::gridfs::upload const& options = {});
440
457 open_download_stream(bsoncxx::v_noabi::types::bson_value::view id);
458
479 open_download_stream(client_session const& session, bsoncxx::v_noabi::types::bson_value::view id);
480
502 download_to_stream(bsoncxx::v_noabi::types::bson_value::view id, std::ostream* destination);
503
512 bsoncxx::v_noabi::types::bson_value::view id,
513 std::ostream* destination,
514 std::size_t start,
515 std::size_t end);
516
542 client_session const& session,
543 bsoncxx::v_noabi::types::bson_value::view id,
544 std::ostream* destination);
545
554 client_session const& session,
555 bsoncxx::v_noabi::types::bson_value::view id,
556 std::ostream* destination,
557 std::size_t start,
558 std::size_t end);
559
571 MONGOCXX_ABI_EXPORT_CDECL(void) delete_file(bsoncxx::v_noabi::types::bson_value::view id);
572
588 delete_file(client_session const& session, bsoncxx::v_noabi::types::bson_value::view id);
589
610 find(bsoncxx::v_noabi::document::view_or_value filter, options::find const& options = {});
611
637 client_session const& session,
638 bsoncxx::v_noabi::document::view_or_value filter,
639 options::find const& options = {});
640
648
649 private:
650 friend ::mongocxx::v_noabi::database;
651
652 // Constructs a new GridFS bucket. Throws if options are invalid.
654
655 void create_indexes_if_nonexistent(client_session const* session);
656
657 uploader _open_upload_stream_with_id(
658 client_session const* session,
662
663 void _upload_from_stream_with_id(
664 client_session const* session,
667 std::istream* source,
669
670 downloader _open_download_stream(
671 client_session const* session,
675
676 void _download_to_stream(
677 client_session const* session,
679 std::ostream* destination,
682
683 void _delete_file(client_session const* session, bsoncxx::v_noabi::types::bson_value::view id);
684
685 class impl;
686
687 impl& _get_impl();
688 impl const& _get_impl() const;
689
690 std::unique_ptr<impl> _impl;
691};
692
693} // namespace gridfs
694} // namespace v_noabi
695} // namespace mongocxx
696
698
A polyfill for std::optional<T>.
Definition optional.hpp:800
A polyfill for std::string_view.
Definition string_view.hpp:411
A non-owning variant that can contain any BSON type.
Definition view.hpp:55
bucket() noexcept
Default constructs a bucket object. The bucket is equivalent to the state of a moved from bucket....
Supports MongoDB client session operations.
Definition client_session.hpp:50
A cursor over the documents returned by a query to a MongoDB server.
Definition cursor.hpp:42
A MongoDB database.
Definition database.hpp:46
downloader open_download_stream(bsoncxx::v_noabi::types::bson_value::view id)
Opens a gridfs::downloader to read a GridFS file.
uploader open_upload_stream(bsoncxx::v_noabi::stdx::string_view filename, options::gridfs::upload const &options={})
Opens a gridfs::uploader to create a new GridFS file. The id of the file will be automatically genera...
void upload_from_stream_with_id(bsoncxx::v_noabi::types::bson_value::view id, bsoncxx::v_noabi::stdx::string_view filename, std::istream *source, options::gridfs::upload const &options={})
Creates a new GridFS file with a user-supplied unique id by uploading bytes from an input stream.
void delete_file(bsoncxx::v_noabi::types::bson_value::view id)
Deletes a GridFS file from the bucket.
uploader open_upload_stream_with_id(bsoncxx::v_noabi::types::bson_value::view id, bsoncxx::v_noabi::stdx::string_view filename, options::gridfs::upload const &options={})
Opens a gridfs::uploader to create a new GridFS file.
result::gridfs::upload upload_from_stream(bsoncxx::v_noabi::stdx::string_view filename, std::istream *source, options::gridfs::upload const &options={})
Creates a new GridFS file by uploading bytes from an input stream. The id of the file will be automat...
bucket() noexcept
Default constructs a bucket object. The bucket is equivalent to the state of a moved from bucket....
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, options::find const &options={})
Finds the documents in the files collection of the bucket which match the provided filter.
bsoncxx::v_noabi::stdx::string_view bucket_name() const
Gets the name of the GridFS bucket.
Used to download a GridFS file.
Definition downloader.hpp:48
Used to upload a GridFS file.
Definition uploader.hpp:43
Used by mongocxx::v_noabi::gridfs::bucket.
Definition bucket.hpp:37
Used by mongocxx::v_noabi::gridfs::bucket.
Definition upload.hpp:32
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 export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities related to GridFS.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v_noabi::options::gridfs::bucket.
Provides mongocxx::v_noabi::options::gridfs::upload.
Provides mongocxx::v_noabi::result::gridfs::upload.
Provides bsoncxx::v_noabi::types::bson_value::view.
Provides utilities to upload GridFS files.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.