MongoDB C++ Driver  mongocxx-3.10.2
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 <mongocxx/database-fwd.hpp>
22 #include <mongocxx/gridfs/bucket-fwd.hpp>
23 
24 #include <bsoncxx/document/view_or_value.hpp>
25 #include <bsoncxx/stdx/optional.hpp>
26 #include <bsoncxx/stdx/string_view.hpp>
27 #include <bsoncxx/types/bson_value/view.hpp>
28 #include <mongocxx/cursor.hpp>
29 #include <mongocxx/gridfs/downloader.hpp>
30 #include <mongocxx/gridfs/uploader.hpp>
31 #include <mongocxx/options/find.hpp>
32 #include <mongocxx/options/gridfs/bucket.hpp>
33 #include <mongocxx/options/gridfs/upload.hpp>
34 #include <mongocxx/result/gridfs/upload.hpp>
35 #include <mongocxx/stdx.hpp>
36 
37 #include <mongocxx/config/prelude.hpp>
38 
39 namespace mongocxx {
40 namespace v_noabi {
41 namespace gridfs {
42 
63 class 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 
130  uploader open_upload_stream(stdx::string_view filename,
131  const options::gridfs::upload& options = {});
132 
164  stdx::string_view filename,
165  const options::gridfs::upload& options = {});
169 
201  stdx::string_view filename,
202  const options::gridfs::upload& options = {});
203 
238  stdx::string_view filename,
239  const options::gridfs::upload& options = {});
243 
287  result::gridfs::upload upload_from_stream(stdx::string_view filename,
288  std::istream* source,
289  const options::gridfs::upload& options = {});
290 
336  stdx::string_view filename,
337  std::istream* source,
338  const options::gridfs::upload& options = {});
342 
387  stdx::string_view filename,
388  std::istream* source,
389  const options::gridfs::upload& options = {});
390 
437  stdx::string_view filename,
438  std::istream* source,
439  const options::gridfs::upload& options = {});
443 
462 
487 
511  std::ostream* destination);
512 
521  std::ostream* destination,
522  std::size_t start,
523  std::size_t end);
524 
548  void download_to_stream(const client_session& session,
550  std::ostream* destination);
551 
552  // clang-format off
559  // clang-format on
560  void download_to_stream(const client_session& session,
562  std::ostream* destination,
563  std::size_t start,
564  std::size_t end);
568 
583 
602 
624  const options::find& options = {});
625 
648  cursor find(const client_session& session,
650  const options::find& options = {});
654 
661  stdx::string_view bucket_name() const;
662 
663  private:
664  friend ::mongocxx::v_noabi::database;
665 
666  // Constructs a new GridFS bucket. Throws if options are invalid.
667  MONGOCXX_PRIVATE bucket(const database& db, const options::gridfs::bucket& options);
668 
669  MONGOCXX_PRIVATE void create_indexes_if_nonexistent(const client_session* session);
670 
671  MONGOCXX_PRIVATE uploader
672  _open_upload_stream_with_id(const client_session* session,
674  stdx::string_view filename,
675  const options::gridfs::upload& options);
676 
677  MONGOCXX_PRIVATE void _upload_from_stream_with_id(const client_session* session,
679  stdx::string_view filename,
680  std::istream* source,
681  const options::gridfs::upload& options);
682 
683  MONGOCXX_PRIVATE downloader _open_download_stream(const client_session* session,
685  stdx::optional<std::size_t> start,
686  stdx::optional<std::size_t> end);
687 
688  MONGOCXX_PRIVATE void _download_to_stream(const client_session* session,
690  std::ostream* destination,
691  stdx::optional<std::size_t> start,
692  stdx::optional<std::size_t> end);
693 
694  MONGOCXX_PRIVATE void _delete_file(const client_session* session,
696 
697  class MONGOCXX_PRIVATE impl;
698 
699  MONGOCXX_PRIVATE impl& _get_impl();
700  MONGOCXX_PRIVATE const impl& _get_impl() const;
701 
702  std::unique_ptr<impl> _impl;
703 };
704 
705 } // namespace gridfs
706 } // namespace v_noabi
707 } // namespace mongocxx
708 
709 #include <mongocxx/config/postlude.hpp>
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:47
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:46
Class representing a GridFS bucket.
Definition: bucket.hpp:63
void download_to_stream(const client_session &session, bsoncxx::v_noabi::types::bson_value::view id, std::ostream *destination, std::size_t start, std::size_t end)
Downloads the contents of a stored GridFS file from the bucket and writes it to a stream.
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.
void delete_file(const client_session &session, bsoncxx::v_noabi::types::bson_value::view id)
Deletes a GridFS file from the bucket.
stdx::string_view bucket_name() const
Gets the name of the GridFS bucket.
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.
void delete_file(bsoncxx::v_noabi::types::bson_value::view id)
Deletes a GridFS file from the bucket.
downloader open_download_stream(const client_session &session, bsoncxx::v_noabi::types::bson_value::view id)
Opens a gridfs::downloader to read a GridFS file.
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.
bucket() noexcept
Default constructs a bucket object.
cursor find(const client_session &session, 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.
void download_to_stream(const client_session &session, 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.
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.
void download_to_stream(bsoncxx::v_noabi::types::bson_value::view id, std::ostream *destination, std::size_t start, std::size_t end)
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.
uploader open_upload_stream_with_id(const client_session &session, 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.
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.
void upload_from_stream_with_id(const client_session &session, 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.
Class used to download a GridFS file.
Definition: downloader.hpp:48
Class used to upload a GridFS file.
Definition: uploader.hpp:43
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:39
Class representing the optional arguments to a MongoDB GridFS bucket creation operation.
Definition: bucket.hpp:37
Class representing the optional arguments to a MongoDB GridFS upload operation.
Definition: upload.hpp:33
Class representing the result of a GridFS upload operation.
Definition: upload.hpp:30
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19