MongoDB C++ Driver  mongocxx-3.6.2
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/gridfs/bucket.hpp>
27 #include <mongocxx/read_preference.hpp>
28 #include <mongocxx/write_concern.hpp>
29 
30 #include <mongocxx/config/prelude.hpp>
31 
32 namespace mongocxx {
33 MONGOCXX_INLINE_NAMESPACE_BEGIN
34 
35 class client;
36 
43 class MONGOCXX_API database {
44  public:
50  database() noexcept;
51 
55  database(database&&) noexcept;
56 
60  database& operator=(database&&) noexcept;
61 
65  database(const database&);
66 
70  database& operator=(const database&);
71 
76 
81  explicit operator bool() const noexcept;
82 
106  cursor aggregate(const pipeline& pipeline,
107  const options::aggregate& options = options::aggregate());
108 
132  cursor aggregate(const client_session& session,
133  const pipeline& pipeline,
134  const options::aggregate& options = options::aggregate());
138 
151  bsoncxx::document::value run_command(bsoncxx::document::view_or_value command);
152 
164  bsoncxx::document::value run_command(const client_session& session,
165  bsoncxx::document::view_or_value command);
166 
178  bsoncxx::document::value run_command(bsoncxx::document::view_or_value command,
179  uint32_t server_id);
183 
203  class collection create_collection(stdx::string_view name,
204  bsoncxx::document::view_or_value collection_options = {},
205  const stdx::optional<write_concern>& write_concern = {});
206 
226  class collection create_collection(const client_session& session,
227  stdx::string_view name,
228  bsoncxx::document::view_or_value collection_options = {},
229  const stdx::optional<write_concern>& write_concern = {});
230 
252  MONGOCXX_DEPRECATED class collection create_collection(
253  bsoncxx::string::view_or_value name,
254  const options::create_collection_deprecated& collection_options,
255  const stdx::optional<write_concern>& write_concern = {}) {
256  return create_collection_deprecated(name, collection_options, write_concern);
257  }
258 
259  class collection create_collection_deprecated(
260  bsoncxx::string::view_or_value name,
261  const options::create_collection_deprecated& collection_options,
262  const stdx::optional<write_concern>& write_concern = {});
263 
287  MONGOCXX_DEPRECATED class collection create_collection(
288  const client_session& session,
290  const options::create_collection_deprecated& collection_options,
291  const stdx::optional<write_concern>& write_concern = {}) {
292  return create_collection_deprecated(session, name, collection_options, write_concern);
293  }
294 
295  class collection create_collection_deprecated(
296  const client_session& session,
298  const options::create_collection_deprecated& collection_options,
299  const stdx::optional<write_concern>& write_concern = {});
300 
304 
320  void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
321 
337  void drop(const client_session& session,
338  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
342 
354 
368 
383 
397  std::vector<std::string> list_collection_names(bsoncxx::document::view_or_value filter = {});
398 
414  std::vector<std::string> list_collection_names(const client_session& session,
416 
420 
426  stdx::string_view name() const;
427 
440  void read_concern(class read_concern rc);
441 
450  class read_concern read_concern() const;
451 
464 
472  class read_preference read_preference() const;
473 
481  void write_concern(class write_concern wc);
482 
488  class write_concern write_concern() const;
489 
497  class collection collection(bsoncxx::string::view_or_value name) const;
498 
507  MONGOCXX_INLINE class collection operator[](bsoncxx::string::view_or_value name) const;
508 
523  class gridfs::bucket gridfs_bucket(
524  const options::gridfs::bucket& options = options::gridfs::bucket()) const;
525 
540  change_stream watch(const options::change_stream& options = {});
541 
553  change_stream watch(const client_session& session, const options::change_stream& options = {});
554 
571  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
572 
588  change_stream watch(const client_session& session,
589  const pipeline& pipe,
590  const options::change_stream& options = {});
591 
595 
596  private:
597  friend class client;
598  friend class collection;
599 
600  MONGOCXX_PRIVATE database(const class client& client, bsoncxx::string::view_or_value name);
601 
602  MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
603  const pipeline& pipeline,
604  const options::aggregate& options);
605 
606  MONGOCXX_PRIVATE bsoncxx::document::value _run_command(
607  const client_session* session, bsoncxx::document::view_or_value command);
608 
609  MONGOCXX_PRIVATE class collection _create_collection(
610  const client_session* session,
611  stdx::string_view name,
612  bsoncxx::document::view_or_value collection_options,
613  const stdx::optional<class write_concern>& write_concern);
614 
615  MONGOCXX_PRIVATE class collection _create_collection_deprecated(
616  const client_session* session,
617  bsoncxx::string::view_or_value name,
618  const options::create_collection_deprecated& collection_options,
619  const stdx::optional<class write_concern>& write_concern);
620 
621  MONGOCXX_PRIVATE cursor _list_collections(const client_session* session,
622  bsoncxx::document::view_or_value filter);
623 
624  MONGOCXX_PRIVATE std::vector<std::string> _list_collection_names(
625  const client_session* session, bsoncxx::document::view_or_value filter);
626 
627  MONGOCXX_PRIVATE void _drop(
628  const client_session* session,
629  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
630 
631  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
632  const pipeline& pipe,
633  const options::change_stream& options);
634 
635  class MONGOCXX_PRIVATE impl;
636 
637  MONGOCXX_PRIVATE impl& _get_impl();
638  MONGOCXX_PRIVATE const impl& _get_impl() const;
639 
640  std::unique_ptr<impl> _impl;
641 };
642 
643 MONGOCXX_INLINE collection database::operator[](bsoncxx::string::view_or_value name) const {
644  return collection(name);
645 }
646 
647 MONGOCXX_INLINE_NAMESPACE_END
648 } // namespace mongocxx
649 
650 #include <mongocxx/config/postlude.hpp>
mongocxx::database::list_collections
cursor list_collections(const client_session &session, bsoncxx::document::view_or_value filter={})
Enumerates the collections in this database.
mongocxx::database::name
stdx::string_view name() const
Get the name of this database.
mongocxx::change_stream
Definition: change_stream.hpp:31
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::view_or_value< document::view, document::value >
mongocxx::options::create_collection_deprecated
Class representing the optional arguments to a MongoDB createCollection command.
Definition: create_collection.hpp:35
mongocxx::write_concern
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:56
mongocxx::database::list_collection_names
std::vector< std::string > list_collection_names(bsoncxx::document::view_or_value filter={})
Enumerates the collection names in this database.
mongocxx::database::read_preference
class read_preference read_preference() const
The current read preference for this database.
mongocxx::database::read_concern
class read_concern read_concern() const
The current read concern for this database.
mongocxx::client
Class representing a client connection to MongoDB.
Definition: client.hpp:58
mongocxx::read_concern
A class to represent the read concern.
Definition: read_concern.hpp:54
bsoncxx::document::value
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
mongocxx::database::database
database() noexcept
Default constructs a new database.
mongocxx::read_preference
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:62
bsoncxx::string::view_or_value
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
mongocxx::database::list_collection_names
std::vector< std::string > list_collection_names(const client_session &session, bsoncxx::document::view_or_value filter={})
Enumerates the collection names in this database.
mongocxx::gridfs::bucket
Class representing a GridFS bucket.
Definition: bucket.hpp:62
mongocxx::database::write_concern
class write_concern write_concern() const
The current write_concern for this database.
mongocxx::database::list_collections
cursor list_collections(bsoncxx::document::view_or_value filter={})
Enumerates the collections in this database.
mongocxx::pipeline
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:38
mongocxx::client_session
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:39
mongocxx::database
Class representing a MongoDB database.
Definition: database.hpp:43
mongocxx::database::drop
void drop(const client_session &session, const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops the database and all its collections.
mongocxx::database::drop
void drop(const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops the database and all its collections.
mongocxx::collection
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:81
mongocxx::database::has_collection
bool has_collection(bsoncxx::string::view_or_value name) const
Checks whether this database contains a collection having the given name.
mongocxx::cursor
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36