MongoDB C++ Driver  mongocxx-3.7.0
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/optional.hpp>
23 #include <bsoncxx/stdx/string_view.hpp>
24 #include <bsoncxx/types/bson_value/view.hpp>
25 #include <mongocxx/cursor.hpp>
26 #include <mongocxx/gridfs/downloader.hpp>
27 #include <mongocxx/gridfs/uploader.hpp>
28 #include <mongocxx/options/find.hpp>
29 #include <mongocxx/options/gridfs/bucket.hpp>
30 #include <mongocxx/options/gridfs/upload.hpp>
31 #include <mongocxx/result/gridfs/upload.hpp>
32 #include <mongocxx/stdx.hpp>
33 
34 #include <mongocxx/config/prelude.hpp>
35 
36 namespace mongocxx {
37 MONGOCXX_INLINE_NAMESPACE_BEGIN
38 
39 class database;
40 
41 namespace gridfs {
42 
63 class MONGOCXX_API bucket {
64  public:
70  bucket() noexcept;
71 
75  bucket(bucket&&) noexcept;
76 
80  bucket& operator=(bucket&&) noexcept;
81 
85  bucket(const bucket&);
86 
90  bucket& operator=(const bucket&);
91 
95  ~bucket();
96 
100  explicit operator bool() const noexcept;
101 
129  uploader open_upload_stream(stdx::string_view filename,
130  const options::gridfs::upload& options = {});
131 
161  uploader open_upload_stream(const client_session& session,
162  stdx::string_view filename,
163  const options::gridfs::upload& options = {});
167 
197  uploader open_upload_stream_with_id(bsoncxx::types::bson_value::view id,
198  stdx::string_view filename,
199  const options::gridfs::upload& options = {});
200 
232  uploader open_upload_stream_with_id(const client_session& session,
234  stdx::string_view filename,
235  const options::gridfs::upload& options = {});
239 
282  result::gridfs::upload upload_from_stream(stdx::string_view filename,
283  std::istream* source,
284  const options::gridfs::upload& options = {});
285 
329  result::gridfs::upload upload_from_stream(const client_session& session,
330  stdx::string_view filename,
331  std::istream* source,
332  const options::gridfs::upload& options = {});
336 
379  void upload_from_stream_with_id(bsoncxx::types::bson_value::view id,
380  stdx::string_view filename,
381  std::istream* source,
382  const options::gridfs::upload& options = {});
383 
427  void upload_from_stream_with_id(const client_session& session,
429  stdx::string_view filename,
430  std::istream* source,
431  const options::gridfs::upload& options = {});
435 
453  downloader open_download_stream(bsoncxx::types::bson_value::view id);
454 
474  downloader open_download_stream(const client_session& session,
479 
502  void download_to_stream(bsoncxx::types::bson_value::view id, std::ostream* destination);
503  void download_to_stream(bsoncxx::types::bson_value::view id,
504  std::ostream* destination,
505  std::size_t start,
506  std::size_t end);
507 
531  void download_to_stream(const client_session& session,
533  std::ostream* destination);
534  void download_to_stream(const client_session& session,
536  std::ostream* destination,
537  std::size_t start,
538  std::size_t end);
542 
556  void delete_file(bsoncxx::types::bson_value::view id);
557 
572  void delete_file(const client_session& session, bsoncxx::types::bson_value::view id);
576 
597  cursor find(bsoncxx::document::view_or_value filter, const options::find& options = {});
598 
621  cursor find(const client_session& session,
623  const options::find& options = {});
627 
634  stdx::string_view bucket_name() const;
635 
636  private:
637  friend class mongocxx::database;
638 
639  // Constructs a new GridFS bucket. Throws if options are invalid.
640  MONGOCXX_PRIVATE bucket(const database& db, const options::gridfs::bucket& options);
641 
642  MONGOCXX_PRIVATE void create_indexes_if_nonexistent(const client_session* session);
643 
644  MONGOCXX_PRIVATE uploader _open_upload_stream_with_id(const client_session* session,
646  stdx::string_view filename,
647  const options::gridfs::upload& options);
648 
649  MONGOCXX_PRIVATE void _upload_from_stream_with_id(const client_session* session,
651  stdx::string_view filename,
652  std::istream* source,
653  const options::gridfs::upload& options);
654 
655  MONGOCXX_PRIVATE downloader _open_download_stream(const client_session* session,
657  stdx::optional<std::size_t> start,
658  stdx::optional<std::size_t> end);
659 
660  MONGOCXX_PRIVATE void _download_to_stream(const client_session* session,
662  std::ostream* destination,
663  stdx::optional<std::size_t> start,
664  stdx::optional<std::size_t> end);
665 
666  MONGOCXX_PRIVATE void _delete_file(const client_session* session,
668 
669  class MONGOCXX_PRIVATE impl;
670 
671  MONGOCXX_PRIVATE impl& _get_impl();
672  MONGOCXX_PRIVATE const impl& _get_impl() const;
673 
674  std::unique_ptr<impl> _impl;
675 };
676 
677 } // namespace gridfs
678 MONGOCXX_INLINE_NAMESPACE_END
679 } // namespace mongocxx
680 
681 #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
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx::view_or_value< document::view, document::value >
mongocxx::options::find
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:37
mongocxx::gridfs::bucket
Class representing a GridFS bucket.
Definition: bucket.hpp:63
mongocxx::client_session
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition: client_session.hpp:40
mongocxx::gridfs::downloader
Class used to download a GridFS file.
Definition: downloader.hpp:42
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::cursor
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36
bsoncxx::types::bson_value::view
A view-only variant that can contain any BSON type.
Definition: view.hpp:44