MongoDB C++ Driver  mongocxx-3.10.2
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 <mongocxx/client-fwd.hpp>
21 #include <mongocxx/client_encryption-fwd.hpp>
22 #include <mongocxx/collection-fwd.hpp>
23 #include <mongocxx/database-fwd.hpp>
24 
25 #include <bsoncxx/document/view_or_value.hpp>
26 #include <bsoncxx/string/view_or_value.hpp>
27 #include <mongocxx/client_session.hpp>
28 #include <mongocxx/collection.hpp>
29 #include <mongocxx/gridfs/bucket.hpp>
30 #include <mongocxx/options/create_collection.hpp>
31 #include <mongocxx/options/gridfs/bucket.hpp>
32 #include <mongocxx/read_preference.hpp>
33 #include <mongocxx/write_concern.hpp>
34 
35 #include <mongocxx/config/prelude.hpp>
36 
37 namespace mongocxx {
38 namespace v_noabi {
39 
46 class database {
47  public:
53  database() noexcept;
54 
58  database(database&&) noexcept;
59 
63  database& operator=(database&&) noexcept;
64 
68  database(const database&);
69 
73  database& operator=(const database&);
74 
79 
84  explicit operator bool() const noexcept;
85 
110  const options::aggregate& options = options::aggregate());
111 
136  const pipeline& pipeline,
137  const options::aggregate& options = options::aggregate());
141 
154  bsoncxx::v_noabi::document::value run_command(
155  bsoncxx::v_noabi::document::view_or_value command);
156 
168  bsoncxx::v_noabi::document::value run_command(
169  const client_session& session, bsoncxx::v_noabi::document::view_or_value command);
170 
182  bsoncxx::v_noabi::document::value run_command(bsoncxx::v_noabi::document::view_or_value command,
183  uint32_t server_id);
187 
211  stdx::string_view name,
212  bsoncxx::v_noabi::document::view_or_value collection_options = {},
213  const stdx::optional<write_concern>& write_concern = {});
214 
238  const client_session& session,
239  stdx::string_view name,
240  bsoncxx::v_noabi::document::view_or_value collection_options = {},
241  const stdx::optional<write_concern>& write_concern = {});
242 
266  const options::create_collection_deprecated& collection_options,
267  const stdx::optional<write_concern>& write_concern = {}) {
268  return create_collection_deprecated(name, collection_options, write_concern);
269  }
270 
273  const options::create_collection_deprecated& collection_options,
274  const stdx::optional<write_concern>& write_concern = {});
275 
300  const client_session& session,
302  const options::create_collection_deprecated& collection_options,
303  const stdx::optional<write_concern>& write_concern = {}) {
304  return create_collection_deprecated(session, name, collection_options, write_concern);
305  }
306 
331  const client_session& session,
333  const options::create_collection_deprecated& collection_options,
334  const stdx::optional<write_concern>& write_concern = {});
335 
339 
355  void drop(const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>&
356  write_concern = {});
357 
373  void drop(const client_session& session,
374  const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>&
375  write_concern = {});
379 
391 
405 
420 
434  std::vector<std::string> list_collection_names(
436 
452  std::vector<std::string> list_collection_names(
453  const client_session& session, bsoncxx::v_noabi::document::view_or_value filter = {});
454 
458 
464  stdx::string_view name() const;
465 
479 
489 
502 
511 
520 
527 
536 
547 
563  const options::gridfs::bucket& options = options::gridfs::bucket()) const;
564 
580 
592  change_stream watch(const client_session& session, const options::change_stream& options = {});
593 
610  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
611 
628  const pipeline& pipe,
629  const options::change_stream& options = {});
630 
634 
635  private:
636  friend ::mongocxx::v_noabi::client_encryption;
637  friend ::mongocxx::v_noabi::client;
638  friend ::mongocxx::v_noabi::collection;
639 
640  MONGOCXX_PRIVATE database(const mongocxx::v_noabi::client& client,
642 
643  MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
644  const pipeline& pipeline,
645  const options::aggregate& options);
646 
647  MONGOCXX_PRIVATE bsoncxx::v_noabi::document::value _run_command(
649 
650  MONGOCXX_PRIVATE mongocxx::v_noabi::collection _create_collection(
651  const client_session* session,
652  stdx::string_view name,
654  const stdx::optional<mongocxx::v_noabi::write_concern>& write_concern);
655 
656  MONGOCXX_PRIVATE mongocxx::v_noabi::collection _create_collection_deprecated(
657  const client_session* session,
659  const options::create_collection_deprecated& collection_options,
660  const stdx::optional<mongocxx::v_noabi::write_concern>& write_concern);
661 
662  MONGOCXX_PRIVATE cursor _list_collections(const client_session* session,
664 
665  MONGOCXX_PRIVATE std::vector<std::string> _list_collection_names(
667 
668  MONGOCXX_PRIVATE void _drop(
669  const client_session* session,
670  const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>& write_concern);
671 
672  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
673  const pipeline& pipe,
674  const options::change_stream& options);
675 
676  class MONGOCXX_PRIVATE impl;
677 
678  MONGOCXX_PRIVATE impl& _get_impl();
679  MONGOCXX_PRIVATE const impl& _get_impl() const;
680 
681  std::unique_ptr<impl> _impl;
682 };
683 
686  return collection(name);
687 }
688 
689 } // namespace v_noabi
690 } // namespace mongocxx
691 
692 #include <mongocxx/config/postlude.hpp>
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:38
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:38
Class representing a MongoDB change stream.
Definition: change_stream.hpp:35
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition: client_session.hpp:47
Class representing a client connection to MongoDB.
Definition: client.hpp:61
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:86
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
void read_concern(mongocxx::v_noabi::read_concern rc)
Sets the read_concern for this database.
bsoncxx::v_noabi::document::value run_command(bsoncxx::v_noabi::document::view_or_value command)
Runs a command against this database.
mongocxx::v_noabi::collection operator[](bsoncxx::v_noabi::string::view_or_value name) const
Allows the db["collection_name"] syntax to be used to access a collection within this database.
Definition: database.hpp:684
stdx::string_view name() const
Get the name of this database.
void write_concern(mongocxx::v_noabi::write_concern wc)
Sets the write_concern for this database.
cursor list_collections(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter={})
Enumerates the collections in this database.
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this database.
cursor aggregate(const pipeline &pipeline, const options::aggregate &options=options::aggregate())
Runs an aggregation framework pipeline against this database for pipeline stages that do not require ...
mongocxx::v_noabi::collection create_collection(const client_session &session, stdx::string_view name, bsoncxx::v_noabi::document::view_or_value collection_options={}, const stdx::optional< write_concern > &write_concern={})
Explicitly creates a collection in this database with the specified options.
change_stream watch(const options::change_stream &options={})
Gets a change stream on this database with an empty pipeline.
std::vector< std::string > list_collection_names(bsoncxx::v_noabi::document::view_or_value filter={})
Enumerates the collection names in this database.
mongocxx::v_noabi::collection create_collection(stdx::string_view name, bsoncxx::v_noabi::document::view_or_value collection_options={}, const stdx::optional< write_concern > &write_concern={})
Explicitly creates a collection in this database with the specified options.
void drop(const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > &write_concern={})
Drops the database and all its collections.
database() noexcept
Default constructs a new database.
std::vector< std::string > list_collection_names(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter={})
Enumerates the collection names in this database.
cursor list_collections(bsoncxx::v_noabi::document::view_or_value filter={})
Enumerates the collections in this database.
mongocxx::v_noabi::read_preference read_preference() const
The current read preference for this database.
mongocxx::v_noabi::read_concern read_concern() const
The current read concern for this database.
void read_preference(mongocxx::v_noabi::read_preference rp)
Sets the read_preference for this database.
mongocxx::v_noabi::collection collection(bsoncxx::v_noabi::string::view_or_value name) const
Access a collection (logical grouping of documents) within this database.
change_stream watch(const client_session &session, const options::change_stream &options={})
void drop(const client_session &session, const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > &write_concern={})
Drops the database and all its collections.
mongocxx::v_noabi::collection create_collection(const client_session &session, bsoncxx::v_noabi::string::view_or_value name, const options::create_collection_deprecated &collection_options, const stdx::optional< write_concern > &write_concern={})
Explicitly creates a collection in this database with the specified options.
Definition: database.hpp:299
mongocxx::v_noabi::collection create_collection_deprecated(bsoncxx::v_noabi::string::view_or_value name, const options::create_collection_deprecated &collection_options, const stdx::optional< write_concern > &write_concern={})
Explicitly creates a collection in this database with the specified options.
bool has_collection(bsoncxx::v_noabi::string::view_or_value name) const
Checks whether this database contains a collection having the given name.
mongocxx::v_noabi::write_concern write_concern() const
The current write_concern for this database.
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this database.
mongocxx::v_noabi::collection create_collection(bsoncxx::v_noabi::string::view_or_value name, const options::create_collection_deprecated &collection_options, const stdx::optional< write_concern > &write_concern={})
Explicitly creates a collection in this database with the specified options.
Definition: database.hpp:264
mongocxx::v_noabi::collection create_collection_deprecated(const client_session &session, bsoncxx::v_noabi::string::view_or_value name, const options::create_collection_deprecated &collection_options, const stdx::optional< write_concern > &write_concern={})
Explicitly creates a collection in this database with the specified options.
gridfs::bucket gridfs_bucket(const options::gridfs::bucket &options=options::gridfs::bucket()) const
Access a GridFS bucket within this database.
Class representing a GridFS bucket.
Definition: bucket.hpp:63
Class representing the optional arguments to a MongoDB aggregation operation.
Definition: aggregate.hpp:43
Class representing MongoDB change stream options.
Definition: change_stream.hpp:39
Class representing the optional arguments to a MongoDB createCollection command.
Definition: create_collection.hpp:35
Class representing the optional arguments to a MongoDB GridFS bucket creation operation.
Definition: bucket.hpp:37
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:39
A class to represent the read concern.
Definition: read_concern.hpp:56
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:63
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:58
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19