MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
database.hpp
Go to the documentation of this file.
1// Copyright 2009-present 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 <mongocxx/database-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/database.hpp> // IWYU pragma: export
22
23#include <cstdint>
24#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
25#include <string>
26#include <utility>
27#include <vector>
28
29#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
30#include <mongocxx/client_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
32
38
42#include <mongocxx/cursor.hpp>
47#include <mongocxx/pipeline.hpp>
51
53
54namespace mongocxx {
55namespace v_noabi {
56
63class database {
64 private:
65 v1::database _db;
66
67 public:
73 database() noexcept {}
74
78 database(database&& other) noexcept = default;
79
83 database& operator=(database&& other) noexcept = default;
84
89
93 MONGOCXX_ABI_EXPORT_CDECL(database&) operator=(database const& other);
94
98 ~database() = default;
99
103 /* explicit(false) */ database(v1::database database) : _db{std::move(database)} {}
104
113 explicit operator v1::database() && {
114 return std::move(_db);
115 }
116
120 explicit operator v1::database() const& {
121 return _db;
122 }
123
128 explicit operator bool() const noexcept {
129 return _db.operator bool();
130 }
131
156
183 v_noabi::client_session const& session,
184 v_noabi::pipeline const& pipeline,
185 v_noabi::options::aggregate const& options = {});
186
199 run_command(bsoncxx::v_noabi::document::view_or_value command);
200
213 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
214 run_command(v_noabi::client_session const& session, bsoncxx::v_noabi::document::view_or_value command);
215
228 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
229 run_command(bsoncxx::v_noabi::document::view_or_value command, std::uint32_t server_id);
230
253 bsoncxx::v_noabi::stdx::string_view name,
254 bsoncxx::v_noabi::document::view_or_value collection_options = {},
256
281 v_noabi::client_session const& session,
282 bsoncxx::v_noabi::stdx::string_view name,
283 bsoncxx::v_noabi::document::view_or_value collection_options = {},
285
300 drop(bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> const& write_concern = {});
301
319 v_noabi::client_session const& session,
320 bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> const& write_concern = {});
321
333 has_collection(bsoncxx::v_noabi::string::view_or_value name) const;
334
347 list_collections(bsoncxx::v_noabi::document::view_or_value filter = {});
348
363 list_collections(v_noabi::client_session const& session, bsoncxx::v_noabi::document::view_or_value filter = {});
364
379 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
380 list_collection_names(bsoncxx::v_noabi::document::view_or_value filter = {});
381
398 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
400 v_noabi::client_session const& session,
401 bsoncxx::v_noabi::document::view_or_value filter = {});
402
409
424
434
448
458
467
474
483 collection(bsoncxx::v_noabi::string::view_or_value name) const;
484
493 v_noabi::collection operator[](bsoncxx::v_noabi::string::view_or_value name) const {
494 return this->collection(name);
495 }
496
512 gridfs_bucket(v_noabi::options::gridfs::bucket const& options = {}) const;
513
528
543
563
582 v_noabi::client_session const& session,
583 v_noabi::pipeline const& pipe,
584 v_noabi::options::change_stream const& options = {});
585
586 class internal;
587};
588
589} // namespace v_noabi
590} // namespace mongocxx
591
592namespace mongocxx {
593namespace v_noabi {
594
599 return {std::move(v)};
600}
601
606 return v1::database{std::move(v)};
607}
608
609} // namespace v_noabi
610} // namespace mongocxx
611
613
Provides mongocxx::v_noabi::options::aggregate.
A polyfill for std::optional<T>.
Definition optional.hpp:799
A polyfill for std::string_view.
Definition string_view.hpp:412
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:48
database() noexcept
Default constructs a new database. The database is not valid for use and is equivalent to the state o...
Definition database.hpp:73
A MongoDB database.
Definition database.hpp:57
A MongoDB change stream.
Definition change_stream.hpp:44
Supports MongoDB client session operations.
Definition client_session.hpp:58
A MongoDB collection.
Definition collection.hpp:98
A cursor over the documents returned by a query to a MongoDB server.
Definition cursor.hpp:50
A MongoDB database.
Definition database.hpp:63
v_noabi::cursor aggregate(v_noabi::pipeline const &pipeline, v_noabi::options::aggregate const &options={})
Runs an aggregation framework pipeline against this database for pipeline stages that do not require ...
bsoncxx::v_noabi::document::value run_command(bsoncxx::v_noabi::document::view_or_value command)
Runs a command against this database.
v_noabi::collection create_collection(bsoncxx::v_noabi::stdx::string_view name, bsoncxx::v_noabi::document::view_or_value collection_options={}, bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const &write_concern={})
Explicitly creates a collection in this database with the specified options.
v_noabi::read_preference read_preference() const
The current read preference for this database.
bsoncxx::v_noabi::stdx::string_view name() const
Get the name of this database.
v_noabi::gridfs::bucket gridfs_bucket(v_noabi::options::gridfs::bucket const &options={}) const
Access a GridFS bucket within this database.
database & operator=(database &&other) noexcept=default
Move assigns a database.
void drop(bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const &write_concern={})
Drops the database and all its collections.
v_noabi::collection collection(bsoncxx::v_noabi::string::view_or_value name) const
Access a collection (logical grouping of documents) within this database.
std::vector< std::string > list_collection_names(bsoncxx::v_noabi::document::view_or_value filter={})
Enumerates the collection names in this database.
database(database &&other) noexcept=default
Move constructs a database.
database() noexcept
Default constructs a new database. The database is not valid for use and is equivalent to the state o...
Definition database.hpp:73
void read_preference(v_noabi::read_preference rp)
Sets the read_preference for this database.
v_noabi::cursor list_collections(bsoncxx::v_noabi::document::view_or_value filter={})
Enumerates the collections in this database.
void read_concern(v_noabi::read_concern rc)
Sets the read_concern for this database.
v_noabi::write_concern write_concern() const
The current write_concern for this database.
v_noabi::change_stream watch(v_noabi::options::change_stream const &options={})
Gets a change stream on this database with an empty pipeline. Change streams are only supported with ...
v_noabi::read_concern read_concern() const
The current read concern for this database.
void write_concern(v_noabi::write_concern wc)
Sets the write_concern for this database.
bool has_collection(bsoncxx::v_noabi::string::view_or_value name) const
Checks whether this database contains a collection having the given name.
A GridFS bucket.
Definition bucket.hpp:74
Used by change streams.
Definition change_stream.hpp:52
A MongoDB aggregation pipeline.
Definition pipeline.hpp:45
Controls the consistency and isolation properties of data read from replica sets and sharded clusters...
Definition read_concern.hpp:54
Describes how MongoDB clients route read operations to the members of a replica set or sharded cluste...
Definition read_preference.hpp:59
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
Provides bsoncxx::v_noabi::document::view_or_value.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities related to GridFS.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides bsoncxx::v_noabi::string::view_or_value.
Provides mongocxx::v1::database.
Provides bsoncxx::v_noabi::document::value.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Provides mongocxx::v_noabi::change_stream.
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::client_encryption.
Provides mongocxx::v_noabi::client_session.
Declares mongocxx::v_noabi::collection.
Provides mongocxx::v_noabi::collection.
Provides mongocxx::v_noabi::cursor.
Declares mongocxx::v_noabi::database.
Provides mongocxx::v_noabi::gridfs::bucket.
Provides mongocxx::v_noabi::options::change_stream.
Provides mongocxx::v_noabi::options::gridfs::bucket.
Provides mongocxx::v_noabi::pipeline.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::read_preference.
Provides mongocxx::v_noabi::write_concern.