MongoDB C++ Driver  mongocxx-3.6.2
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
bucket.hpp
1 // Copyright 2017 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 
21 #include <bsoncxx/document/view_or_value.hpp>
22 #include <bsoncxx/stdx/string_view.hpp>
23 #include <bsoncxx/types/bson_value/view.hpp>
24 #include <mongocxx/cursor.hpp>
25 #include <mongocxx/gridfs/downloader.hpp>
26 #include <mongocxx/gridfs/uploader.hpp>
27 #include <mongocxx/options/find.hpp>
28 #include <mongocxx/options/gridfs/bucket.hpp>
29 #include <mongocxx/options/gridfs/upload.hpp>
30 #include <mongocxx/result/gridfs/upload.hpp>
31 #include <mongocxx/stdx.hpp>
32 
33 #include <mongocxx/config/prelude.hpp>
34 
35 namespace mongocxx {
36 MONGOCXX_INLINE_NAMESPACE_BEGIN
37 
38 class database;
39 
40 namespace gridfs {
41 
62 class MONGOCXX_API bucket {
63  public:
69  bucket() noexcept;
70 
74  bucket(bucket&&) noexcept;
75 
79  bucket& operator=(bucket&&) noexcept;
80 
84  bucket(const bucket&);
85 
89  bucket& operator=(const bucket&);
90 
94  ~bucket();
95 
99  explicit operator bool() const noexcept;
100 
128  uploader open_upload_stream(stdx::string_view filename,
129  const options::gridfs::upload& options = {});
130 
161  stdx::string_view filename,
162  const options::gridfs::upload& options = {});
166 
197  stdx::string_view filename,
198  const options::gridfs::upload& options = {});
199 
233  stdx::string_view filename,
234  const options::gridfs::upload& options = {});
238 
281  result::gridfs::upload upload_from_stream(stdx::string_view filename,
282  std::istream* source,
283  const options::gridfs::upload& options = {});
284 
329  stdx::string_view filename,
330  std::istream* source,
331  const options::gridfs::upload& options = {});
335 
379  stdx::string_view filename,
380  std::istream* source,
381  const options::gridfs::upload& options = {});
382 
428  stdx::string_view filename,
429  std::istream* source,
430  const options::gridfs::upload& options = {});
434 
453 
478 
501  void download_to_stream(bsoncxx::types::bson_value::view id, std::ostream* destination);
502 
526  void download_to_stream(const client_session& session,
528  std::ostream* destination);
532 
547 
566 
588 
611  cursor find(const client_session& session,
613  const options::find& options = {});
617 
624  stdx::string_view bucket_name() const;
625 
626  private:
627  friend class mongocxx::database;
628 
629  // Constructs a new GridFS bucket. Throws if options are invalid.
630  MONGOCXX_PRIVATE bucket(const database& db, const options::gridfs::bucket& options);
631 
632  MONGOCXX_PRIVATE void create_indexes_if_nonexistent(const client_session* session);
633 
634  MONGOCXX_PRIVATE uploader _open_upload_stream_with_id(const client_session* session,
636  stdx::string_view filename,
637  const options::gridfs::upload& options);
638 
639  MONGOCXX_PRIVATE void _upload_from_stream_with_id(const client_session* session,
641  stdx::string_view filename,
642  std::istream* source,
643  const options::gridfs::upload& options);
644 
645  MONGOCXX_PRIVATE downloader _open_download_stream(const client_session* session,
647 
648  MONGOCXX_PRIVATE void _download_to_stream(const client_session* session,
650  std::ostream* destination);
651 
652  MONGOCXX_PRIVATE void _delete_file(const client_session* session,
654 
655  class MONGOCXX_PRIVATE impl;
656 
657  MONGOCXX_PRIVATE impl& _get_impl();
658  MONGOCXX_PRIVATE const impl& _get_impl() const;
659 
660  std::unique_ptr<impl> _impl;
661 };
662 
663 } // namespace gridfs
664 MONGOCXX_INLINE_NAMESPACE_END
665 } // namespace mongocxx
666 
667 #include <mongocxx/config/postlude.hpp>
mongocxx::options::gridfs::bucket
Class representing the optional arguments to a MongoDB GridFS bucket creation operation.
Definition: bucket.hpp:35
mongocxx::gridfs::bucket::open_download_stream
downloader open_download_stream(bsoncxx::types::bson_value::view id)
Opens a gridfs::downloader to read a GridFS file.
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx::view_or_value< document::view, document::value >
mongocxx::gridfs::bucket::download_to_stream
void download_to_stream(const client_session &session, bsoncxx::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.
mongocxx::gridfs::bucket::find
cursor find(bsoncxx::document::view_or_value filter, const options::find &options={})
Finds the documents in the files collection of the bucket which match the provided filter.
mongocxx::gridfs::bucket::upload_from_stream
result::gridfs::upload upload_from_stream(const client_session &session, stdx::string_view filename, std::istream *source, const options::gridfs::upload &options={})
Creates a new GridFS file by uploading bytes from an input stream.
mongocxx::gridfs::bucket::download_to_stream
void download_to_stream(bsoncxx::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.
mongocxx::gridfs::bucket::upload_from_stream_with_id
void upload_from_stream_with_id(const client_session &session, bsoncxx::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.
mongocxx::gridfs::bucket::bucket_name
stdx::string_view bucket_name() const
Gets the name of the GridFS bucket.
mongocxx::gridfs::bucket::bucket
bucket() noexcept
Default constructs a bucket object.
mongocxx::gridfs::bucket::delete_file
void delete_file(const client_session &session, bsoncxx::types::bson_value::view id)
Deletes a GridFS file from the bucket.
mongocxx::gridfs::bucket::delete_file
void delete_file(bsoncxx::types::bson_value::view id)
Deletes a GridFS file from the bucket.
mongocxx::options::find
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:36
mongocxx::gridfs::bucket::open_upload_stream_with_id
uploader open_upload_stream_with_id(bsoncxx::types::bson_value::view id, stdx::string_view filename, const options::gridfs::upload &options={})
Opens a gridfs::uploader to create a new GridFS file.
mongocxx::gridfs::bucket::open_upload_stream
uploader open_upload_stream(const client_session &session, stdx::string_view filename, const options::gridfs::upload &options={})
Opens a gridfs::uploader to create a new GridFS file.
mongocxx::gridfs::bucket
Class representing a GridFS bucket.
Definition: bucket.hpp:62
mongocxx::gridfs::bucket::find
cursor find(const client_session &session, bsoncxx::document::view_or_value filter, const options::find &options={})
Finds the documents in the files collection of the bucket which match the provided filter.
mongocxx::gridfs::bucket::upload_from_stream
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.
mongocxx::gridfs::bucket::upload_from_stream_with_id
void upload_from_stream_with_id(bsoncxx::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.
mongocxx::client_session
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:39
mongocxx::gridfs::downloader
Class used to download a GridFS file.
Definition: downloader.hpp:37
mongocxx::database
Class representing a MongoDB database.
Definition: database.hpp:43
mongocxx::gridfs::uploader
Class used to upload a GridFS file.
Definition: uploader.hpp:40
mongocxx::result::gridfs::upload
Class representing the result of a GridFS upload operation.
Definition: upload.hpp:28
mongocxx::options::gridfs::upload
Class representing the optional arguments to a MongoDB GridFS upload operation.
Definition: upload.hpp:31
mongocxx::gridfs::bucket::open_upload_stream_with_id
uploader open_upload_stream_with_id(const client_session &session, bsoncxx::types::bson_value::view id, stdx::string_view filename, const options::gridfs::upload &options={})
Opens a gridfs::uploader to create a new GridFS file.
mongocxx::cursor
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36
mongocxx::gridfs::bucket::open_download_stream
downloader open_download_stream(const client_session &session, bsoncxx::types::bson_value::view id)
Opens a gridfs::downloader to read a GridFS file.
bsoncxx::types::bson_value::view
A view-only variant that can contain any BSON type.
Definition: view.hpp:44