MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
34
36
37namespace mongocxx {
38namespace v_noabi {
39
46class database {
47 public:
54
59
64
69
74
79
84 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
85
110
137 client_session const& session,
138 pipeline const& pipeline,
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(client_session const& 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
207 bsoncxx::v_noabi::stdx::string_view name,
208 bsoncxx::v_noabi::document::view_or_value collection_options = {},
210
235 client_session const& session,
236 bsoncxx::v_noabi::stdx::string_view name,
237 bsoncxx::v_noabi::document::view_or_value collection_options = {},
239
255
273 client_session const& session,
274 bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern> const& write_concern = {});
275
287 has_collection(bsoncxx::v_noabi::string::view_or_value name) const;
288
301 list_collections(bsoncxx::v_noabi::document::view_or_value filter = {});
302
317 list_collections(client_session const& session, bsoncxx::v_noabi::document::view_or_value filter = {});
318
333 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
334 list_collection_names(bsoncxx::v_noabi::document::view_or_value filter = {});
335
352 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
353 list_collection_names(client_session const& session, bsoncxx::v_noabi::document::view_or_value filter = {});
354
361
376
386
400
410
419
426
435 collection(bsoncxx::v_noabi::string::view_or_value name) const;
436
445 mongocxx::v_noabi::collection operator[](bsoncxx::v_noabi::string::view_or_value name) const {
446 return collection(name);
447 }
448
464 gridfs_bucket(options::gridfs::bucket const& options = options::gridfs::bucket()) const;
465
480
494 watch(client_session const& session, options::change_stream const& options = {});
495
514 watch(pipeline const& pipe, options::change_stream const& options = {});
515
533 watch(client_session const& session, pipeline const& pipe, options::change_stream const& options = {});
534
535 private:
536 friend ::mongocxx::v_noabi::client_encryption;
537 friend ::mongocxx::v_noabi::client;
538 friend ::mongocxx::v_noabi::collection;
539
541
542 cursor _aggregate(client_session const* session, pipeline const& pipeline, options::aggregate const& options);
543
545 client_session const* session,
547
548 mongocxx::v_noabi::collection _create_collection(
549 client_session const* session,
553
554 cursor _list_collections(client_session const* session, bsoncxx::v_noabi::document::view_or_value filter);
555
556 std::vector<std::string> _list_collection_names(
557 client_session const* session,
559
560 void _drop(
561 client_session const* session,
563
564 change_stream _watch(client_session const* session, pipeline const& pipe, options::change_stream const& options);
565
566 class impl;
567
568 impl& _get_impl();
569 impl const& _get_impl() const;
570
571 std::unique_ptr<impl> _impl;
572};
573
574} // namespace v_noabi
575} // namespace mongocxx
576
578
A polyfill for std::optional<T>.
Definition optional.hpp:800
A polyfill for std::string_view.
Definition string_view.hpp:411
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:39
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
database() noexcept
Default constructs a new database. The database is not valid for use and is equivalent to the state o...
A MongoDB change stream.
Definition change_stream.hpp:35
Supports MongoDB client session operations.
Definition client_session.hpp:50
A client connection to a MongoDB server.
Definition client.hpp:61
A MongoDB collection.
Definition collection.hpp:87
A cursor over the documents returned by a query to a MongoDB server.
Definition cursor.hpp:42
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.
change_stream watch(options::change_stream const &options={})
Gets a change stream on this database with an empty pipeline. Change streams are only supported with ...
void write_concern(mongocxx::v_noabi::write_concern wc)
Sets the write_concern for this database.
mongocxx::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< write_concern > const &write_concern={})
Explicitly creates a collection in this database with the specified options.
bsoncxx::v_noabi::stdx::string_view name() const
Get the name of this database.
gridfs::bucket gridfs_bucket(options::gridfs::bucket const &options=options::gridfs::bucket()) const
Access a GridFS bucket 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() 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.
cursor aggregate(pipeline const &pipeline, options::aggregate const &options=options::aggregate())
Runs an aggregation framework pipeline against this database for pipeline stages that do not require ...
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.
void drop(bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > const &write_concern={})
Drops the database and all its collections.
A GridFS bucket.
Definition bucket.hpp:66
Used by MongoDB aggregation operations.
Definition aggregate.hpp:43
Used by change streams.
Definition change_stream.hpp:38
A MongoDB aggregation pipeline.
Definition pipeline.hpp:39
Controls the consistency and isolation properties of data read from replica sets and sharded clusters...
Definition read_concern.hpp:48
Describes how MongoDB clients route read operations to the members of a replica set or sharded cluste...
Definition read_preference.hpp:49
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:48
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.
Declares mongocxx::v_noabi::database.
Provides bsoncxx::v_noabi::document::view_or_value.
Provides mongocxx::v_noabi::gridfs::bucket.
#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.
v_noabi::view_or_value< v_noabi::document::view, v_noabi::document::value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::document::view, v_noabi::document::value>.
Definition view_or_value.hpp:30
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities related to GridFS.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
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.