MongoDB C++ Driver  mongocxx-3.4.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
database.hpp
1 // Copyright 2014 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 <memory>
18 #include <string>
19 
20 #include <bsoncxx/document/view_or_value.hpp>
21 #include <bsoncxx/string/view_or_value.hpp>
22 #include <mongocxx/client_session.hpp>
23 #include <mongocxx/collection.hpp>
24 #include <mongocxx/gridfs/bucket.hpp>
25 #include <mongocxx/options/create_collection.hpp>
26 #include <mongocxx/options/create_view.hpp>
27 #include <mongocxx/options/gridfs/bucket.hpp>
28 #include <mongocxx/read_preference.hpp>
29 #include <mongocxx/write_concern.hpp>
30 
31 #include <mongocxx/config/prelude.hpp>
32 
33 namespace mongocxx {
34 MONGOCXX_INLINE_NAMESPACE_BEGIN
35 
36 class client;
37 
44 class MONGOCXX_API database {
45  public:
51  database() noexcept;
52 
56  database(database&&) noexcept;
57 
61  database& operator=(database&&) noexcept;
62 
66  database(const database&);
67 
71  database& operator=(const database&);
72 
76  ~database();
77 
82  explicit operator bool() const noexcept;
83 
97 
109  bsoncxx::document::value run_command(const client_session& session,
114 
134  class collection create_collection(stdx::string_view name,
135  bsoncxx::document::view_or_value collection_options = {},
136  const stdx::optional<write_concern>& write_concern = {});
137 
157  class collection create_collection(const client_session& session,
158  stdx::string_view name,
159  bsoncxx::document::view_or_value collection_options = {},
160  const stdx::optional<write_concern>& write_concern = {});
161 
183  class collection create_collection(bsoncxx::string::view_or_value name,
184  const options::create_collection& collection_options,
185  const stdx::optional<write_concern>& write_concern = {}) {
186  return create_collection_deprecated(name, collection_options, write_concern);
187  }
188 
189  class collection create_collection_deprecated(
190  bsoncxx::string::view_or_value name,
191  const options::create_collection& collection_options,
192  const stdx::optional<write_concern>& write_concern = {});
193 
217  class collection create_collection(const client_session& session,
219  const options::create_collection& collection_options,
220  const stdx::optional<write_concern>& write_concern = {}) {
221  return create_collection_deprecated(session, name, collection_options, write_concern);
222  }
223 
224  class collection create_collection_deprecated(
225  const client_session& session,
227  const options::create_collection& collection_options,
228  const stdx::optional<write_concern>& write_concern = {});
229 
233 
256  MONGOCXX_DEPRECATED class collection create_view(
257  bsoncxx::string::view_or_value name,
259  const options::create_view& options = options::create_view());
260 
261  class collection create_view_deprecated(
262  bsoncxx::string::view_or_value name,
263  bsoncxx::string::view_or_value view_on,
264  const options::create_view& options = options::create_view());
265 
269 
285  void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
286 
302  void drop(const client_session& session,
303  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
307 
318  bool has_collection(bsoncxx::string::view_or_value name) const;
319 
332  cursor list_collections(bsoncxx::document::view_or_value filter = {});
333 
346  cursor list_collections(const client_session& session,
347  bsoncxx::document::view_or_value filter = {});
348 
362  std::vector<std::string> list_collection_names(bsoncxx::document::view_or_value filter = {});
363 
379  std::vector<std::string> list_collection_names(const client_session& session,
380  bsoncxx::document::view_or_value filter = {});
381 
385 
391  stdx::string_view name() const;
392 
405  void read_concern(class read_concern rc);
406 
415  class read_concern read_concern() const;
416 
428  void read_preference(class read_preference rp);
429 
437  class read_preference read_preference() const;
438 
446  void write_concern(class write_concern wc);
447 
453  class write_concern write_concern() const;
454 
462  class collection collection(bsoncxx::string::view_or_value name) const;
463 
472  MONGOCXX_INLINE class collection operator[](bsoncxx::string::view_or_value name) const;
473 
488  class gridfs::bucket gridfs_bucket(
489  const options::gridfs::bucket& options = options::gridfs::bucket()) const;
490 
505  change_stream watch(const options::change_stream& options = {});
506 
518  change_stream watch(const client_session& session, const options::change_stream& options = {});
519 
536  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
537 
553  change_stream watch(const client_session& session,
554  const pipeline& pipe,
555  const options::change_stream& options = {});
556 
560 
561  private:
562  friend class client;
563  friend class collection;
564 
565  MONGOCXX_PRIVATE database(const class client& client, bsoncxx::string::view_or_value name);
566 
567  MONGOCXX_PRIVATE bsoncxx::document::value _run_command(
568  const client_session* session, bsoncxx::document::view_or_value command);
569 
570  MONGOCXX_PRIVATE class collection _create_collection(
571  const client_session* session,
572  stdx::string_view name,
573  bsoncxx::document::view_or_value collection_options,
574  const stdx::optional<class write_concern>& write_concern);
575 
576  MONGOCXX_PRIVATE class collection _create_collection_deprecated(
577  const client_session* session,
578  bsoncxx::string::view_or_value name,
579  const options::create_collection& collection_options,
580  const stdx::optional<class write_concern>& write_concern);
581 
582  MONGOCXX_PRIVATE cursor _list_collections(const client_session* session,
583  bsoncxx::document::view_or_value filter);
584 
585  MONGOCXX_PRIVATE std::vector<std::string> _list_collection_names(
586  const client_session* session, bsoncxx::document::view_or_value filter);
587 
588  MONGOCXX_PRIVATE void _drop(
589  const client_session* session,
590  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
591 
592  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
593  const pipeline& pipe,
594  const options::change_stream& options);
595 
596  class MONGOCXX_PRIVATE impl;
597 
598  MONGOCXX_PRIVATE impl& _get_impl();
599  MONGOCXX_PRIVATE const impl& _get_impl() const;
600 
601  std::unique_ptr<impl> _impl;
602 };
603 
604 MONGOCXX_INLINE collection database::operator[](bsoncxx::string::view_or_value name) const {
605  return collection(name);
606 }
607 
608 MONGOCXX_INLINE_NAMESPACE_END
609 } // namespace mongocxx
610 
611 #include <mongocxx/config/postlude.hpp>
Class representing the optional arguments to a MongoDB createCollection command.
Definition: create_collection.hpp:31
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
Class representing the optional arguments to a view creation operation.
Definition: create_view.hpp:35
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36
Class representing a client connection to MongoDB.
Definition: client.hpp:57
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:38
Class representing a GridFS bucket.
Definition: bucket.hpp:62
Class representing a MongoDB database.
Definition: database.hpp:44
Definition: change_stream.hpp:31
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:62
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
A class to represent the read concern.
Definition: read_concern.hpp:53
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
Class representing the server-side requirement for reporting the success of a write operation...
Definition: write_concern.hpp:56
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:85