MongoDB C++ Driver mongocxx-3.11.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 <memory>
18#include <string>
19
24
27
35
37
38namespace mongocxx {
39namespace v_noabi {
40
47class database {
48 public:
55
60
65
70
75
80
85 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
86
110 aggregate(const pipeline& pipeline, const options::aggregate& options = options::aggregate());
111
137 aggregate(const client_session& session,
138 const pipeline& pipeline,
139 const options::aggregate& options = options::aggregate());
140
152 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
153 run_command(bsoncxx::v_noabi::document::view_or_value command);
154
167 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
168 run_command(const client_session& session, bsoncxx::v_noabi::document::view_or_value command);
169
182 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
183 run_command(bsoncxx::v_noabi::document::view_or_value command, uint32_t server_id);
184
206 create_collection(stdx::string_view name,
207 bsoncxx::v_noabi::document::view_or_value collection_options = {},
209
234 stdx::string_view name,
235 bsoncxx::v_noabi::document::view_or_value collection_options = {},
237
260 create_collection(bsoncxx::v_noabi::string::view_or_value name,
261 const options::create_collection_deprecated& collection_options,
262 const stdx::optional<write_concern>& write_concern = {}) {
263 return create_collection_deprecated(name, collection_options, write_concern);
264 }
265
267 create_collection_deprecated(bsoncxx::v_noabi::string::view_or_value name,
268 const options::create_collection_deprecated& collection_options,
270
296 bsoncxx::v_noabi::string::view_or_value name,
297 const options::create_collection_deprecated& collection_options,
298 const stdx::optional<write_concern>& write_concern = {}) {
299 return create_collection_deprecated(session, name, collection_options, write_concern);
300 }
301
326 create_collection_deprecated(const client_session& session,
327 bsoncxx::v_noabi::string::view_or_value name,
328 const options::create_collection_deprecated& collection_options,
329 const stdx::optional<write_concern>& write_concern = {});
330
345 drop(const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>& write_concern =
346 {});
347
364 drop(const client_session& session,
365 const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>& write_concern =
366 {});
367
379 has_collection(bsoncxx::v_noabi::string::view_or_value name) const;
380
393 list_collections(bsoncxx::v_noabi::document::view_or_value filter = {});
394
410 bsoncxx::v_noabi::document::view_or_value filter = {});
411
426 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
427 list_collection_names(bsoncxx::v_noabi::document::view_or_value filter = {});
428
445 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
447 bsoncxx::v_noabi::document::view_or_value filter = {});
448
455
470
480
494
504
513
520
529 collection(bsoncxx::v_noabi::string::view_or_value name) const;
530
539 mongocxx::v_noabi::collection operator[](bsoncxx::v_noabi::string::view_or_value name) const {
540 return collection(name);
541 }
542
558 gridfs_bucket(const options::gridfs::bucket& options = options::gridfs::bucket()) const;
559
574
588 watch(const client_session& session, const options::change_stream& options = {});
589
608 watch(const pipeline& pipe, const options::change_stream& options = {});
609
627 watch(const client_session& session,
628 const pipeline& pipe,
629 const options::change_stream& options = {});
630
631 private:
632 friend ::mongocxx::v_noabi::client_encryption;
633 friend ::mongocxx::v_noabi::client;
634 friend ::mongocxx::v_noabi::collection;
635
637
638 cursor _aggregate(const client_session* session,
639 const pipeline& pipeline,
640 const options::aggregate& options);
641
644
645 mongocxx::v_noabi::collection _create_collection(
646 const client_session* session,
650
651 mongocxx::v_noabi::collection _create_collection_deprecated(
652 const client_session* session,
654 const options::create_collection_deprecated& collection_options,
656
657 cursor _list_collections(const client_session* session,
659
660 std::vector<std::string> _list_collection_names(
662
663 void _drop(
664 const client_session* session,
666
667 change_stream _watch(const client_session* session,
668 const pipeline& pipe,
669 const options::change_stream& options);
670
671 class impl;
672
673 impl& _get_impl();
674 const impl& _get_impl() const;
675
676 std::unique_ptr<impl> _impl;
677};
678
679} // namespace v_noabi
680} // namespace mongocxx
681
683
A read-only BSON document that owns its underlying buffer. When a document::value goes out of scope,...
Definition value.hpp:38
A polyfill for std::optional<T>.
Definition optional.hpp:874
A polyfill for std::string_view.
Definition string_view.hpp:503
Class representing a view-or-value variant type for strings.
Definition view_or_value.hpp:41
mongocxx::v_noabi::options::create_collection_deprecated
Definition create_collection.hpp:294
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:48
Class representing a client connection to MongoDB.
Definition client.hpp:62
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:87
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:47
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.
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 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 ...
change_stream watch(const options::change_stream &options={})
Gets a change stream on this database with an empty pipeline. Change streams are only supported with ...
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.
std::vector< std::string > list_collection_names(bsoncxx::v_noabi::document::view_or_value filter={})
Enumerates the collection names in this database.
database() noexcept
Default constructs a new database. The database is not valid for use and is equivalent to the state o...
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.
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.
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:67
Class representing the optional arguments to a MongoDB aggregation operation.
Definition aggregate.hpp:44
Class representing MongoDB change stream options.
Definition change_stream.hpp:40
Class representing the optional arguments to a MongoDB createCollection command.
Definition create_collection.hpp:35
Class representing a MongoDB aggregation pipeline.
Definition pipeline.hpp:39
A class to represent the read concern. Read concern can be set at the client, database,...
Definition read_concern.hpp:58
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:65
Class representing the server-side requirement for reporting the success of a write operation....
Definition write_concern.hpp:61
mongocxx::v_noabi::write_concern
Definition write_concern-fwd.hpp:45
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::options::create_collection.
Declares mongocxx::v_noabi::database.
Provides bsoncxx::v_noabi::document::view_or_value.
Provides mongocxx::v_noabi::gridfs::bucket.
#define MONGOCXX_DEPRECATED
Declares the associated entity as deprecated.
Definition fwd.hpp:258
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:222
The mongocxx macro guard postlude header.
The mongocxx macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v_noabi::options::gridfs::bucket.
Provides mongocxx::v_noabi::read_preference.
Provides bsoncxx::v_noabi::string::view_or_value.
Provides mongocxx::v_noabi::write_concern.