MongoDB C++ Driver current
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/v1/database-fwd.hpp> // IWYU pragma: export
18
19//
20
22
24
31
35
41
42#include <cstdint>
43#include <string>
44#include <system_error>
45#include <vector>
46
47namespace mongocxx {
48namespace v1 {
49
56class database {
57 private:
58 class impl;
59 void* _impl;
60
61 public:
68
76
83 MONGOCXX_ABI_EXPORT_CDECL(database&) operator=(database&& other) noexcept;
84
89
93 MONGOCXX_ABI_EXPORT_CDECL(database&) operator=(database const& other);
94
102
106 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const;
107
116 v1::pipeline const& pipeline,
117 v1::aggregate_options const& opts = {});
118
120 aggregate(v1::client_session const& session, v1::pipeline const& pipeline, v1::aggregate_options const& opts = {});
123
137
139 v1::client_session const& session,
143
157 std::uint32_t server_id);
158
175
177 v1::client_session const& session,
183
195
197 v1::client_session const& session,
201
211
223
225 v1::client_session const& session,
226 bsoncxx::v1::document::view filter = {});
229
241
243 v1::client_session const& session,
244 bsoncxx::v1::document::view filter = {});
247
252
262
267
277
282
292
297
305
313
327
336
338 v1::client_session const& session,
339 v1::change_stream::options const& opts = {});
342
351 v1::pipeline const& pipeline,
352 v1::change_stream::options const& opts = {});
353
355 watch(v1::client_session const& session, v1::pipeline const& pipeline, v1::change_stream::options const& opts = {});
358
366
370 static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
371
375 friend std::error_code make_error_code(errc v) {
376 return {static_cast<int>(v), error_category()};
377 }
378
379 class internal;
380
381 private:
382 /* explicit(false) */ database(void* impl);
383};
384
385} // namespace v1
386} // namespace mongocxx
387
388namespace std {
389
390template <>
391struct is_error_code_enum<mongocxx::v1::database::errc> : true_type {};
392
393} // namespace std
394
396
Provides mongocxx::v1::aggregate_options.
A BSON document.
Definition value.hpp:44
A non-owning, read-only BSON document.
Definition view.hpp:52
A polyfill for std::optional<T>.
Definition optional.hpp:799
A polyfill for std::string_view.
Definition string_view.hpp:412
Options for an "aggregate" command.
Definition aggregate_options.hpp:62
Options for mongocxx::v1::change_stream.
Definition change_stream.hpp:170
A MongoDB change stream.
Definition change_stream.hpp:48
A MongoDB client session.
Definition client_session.hpp:46
A MongoDB collection.
Definition collection.hpp:81
A MongoDB cursor.
Definition cursor.hpp:39
~database()
Destroy this object.
v1::collection create_collection(v1::client_session const &session, bsoncxx::v1::stdx::string_view name, bsoncxx::v1::document::view opts={}, bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
Explicitly create a new collection or view in this database.
v1::collection collection(bsoncxx::v1::stdx::string_view name) const
Access the collection with the given name.
v1::change_stream watch(v1::pipeline const &pipeline, v1::change_stream::options const &opts={})
Return a change stream subscribed to this collection with events filtered/modified by pipeline.
v1::change_stream watch(v1::client_session const &session, v1::change_stream::options const &opts={})
Return a change stream subscribed to this database.
v1::change_stream watch(v1::change_stream::options const &opts={})
Return a change stream subscribed to this database.
std::vector< std::string > list_collection_names(bsoncxx::v1::document::view filter={})
Return an unsorted list of the names of all the collections and views in this database.
v1::write_concern write_concern() const
Return the current default "writeConcern" to use for operations on this database.
v1::cursor list_collections(bsoncxx::v1::document::view filter={})
Return an unsorted list of all collections and views in this database.
bsoncxx::v1::document::value run_command(v1::client_session const &session, bsoncxx::v1::document::view command)
Run an arbitrary database command.
v1::read_concern read_concern() const
Return the current default "readConcern" to use for operations on this database.
bsoncxx::v1::document::value run_command(bsoncxx::v1::document::view command, std::uint32_t server_id)
Run an arbitrary database command against the requested specific server.
database()
Default initialization.
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition database.hpp:375
bsoncxx::v1::stdx::string_view name() const
Return the name of this database.
v1::cursor aggregate(v1::pipeline const &pipeline, v1::aggregate_options const &opts={})
Run an aggregation framework pipeline.
static std::error_category const & error_category()
The error category for mongocxx::v1::database::errc.
void write_concern(v1::write_concern const &wc)
Set the default "writeConcern" to use for operations on this database.
void read_preference(v1::read_preference const &rp)
Set the default "readPreference" to use for operations on this database.
bsoncxx::v1::document::value run_command(bsoncxx::v1::document::view command)
Run an arbitrary database command.
v1::gridfs::bucket gridfs_bucket(v1::gridfs::bucket::options const &opts={}) const
Return a GridFS bucket for this database.
void read_concern(v1::read_concern const &rc)
Set the default "readConcern" to use for operations on this database.
void drop(v1::client_session const &session, bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
Drop this database and all associated data files.
errc
Errors codes which may be returned by mongocxx::v1::database.
Definition database.hpp:362
@ zero
Zero.
Definition database.hpp:363
@ invalid_collection_name
The collection name is not valid.
Definition database.hpp:364
std::vector< std::string > list_collection_names(v1::client_session const &session, bsoncxx::v1::document::view filter={})
Return an unsorted list of the names of all the collections and views in this database.
database(database &&other) noexcept
Move constructor.
v1::cursor list_collections(v1::client_session const &session, bsoncxx::v1::document::view filter={})
Return an unsorted list of all collections and views in this database.
bool has_collection(bsoncxx::v1::stdx::string_view name)
Return true when this database contains a collection with the given name.
v1::read_preference read_preference() const
Return the current default "readPreference" to use for operations on this database.
v1::collection create_collection(bsoncxx::v1::stdx::string_view name, bsoncxx::v1::document::view opts={}, bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
Explicitly create a new collection or view in this database.
void drop(bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
Drop this database and all associated data files.
v1::collection operator[](bsoncxx::v1::stdx::string_view name) const
Equivalent to this->collection(name).
Options for mongocxx::v1::gridfs::bucket.
Definition bucket.hpp:335
A GridFS bucket.
Definition bucket.hpp:60
A MongoDB aggregation pipeline.
Definition pipeline.hpp:41
Options related to a MongoDB Read Concern.
Definition read_concern.hpp:42
Options related to a MongoDB Read Preference.
Definition read_preference.hpp:47
Options related to a MongoDB Write Concern.
Definition write_concern.hpp:47
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard postlude header.
The mongocxx v1 macro guard prelude header.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is guaranteed for documented symbols.
@ mongocxx
From the mongocxx library.
Definition exception.hpp:40
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v1::change_stream.
Declares mongocxx::v1::client_session.
Declares mongocxx::v1::collection.
Declares mongocxx::v1::cursor.
Declares mongocxx::v1::database.
Declares bsoncxx::v1::document::value.
Provides bsoncxx::v1::document::view.
Provides mongocxx::v1::gridfs::bucket.
Declares mongocxx::v1::pipeline.
Declares mongocxx::v1::read_concern.
Declares mongocxx::v1::read_preference.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Provides mongocxx::v1::write_concern.