MongoDB C++ Driver mongocxx-4.0.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
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
109 aggregate(const pipeline& pipeline, const options::aggregate& options = options::aggregate());
110
136 aggregate(const client_session& session,
137 const pipeline& pipeline,
138 const options::aggregate& options = options::aggregate());
139
151 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
152 run_command(bsoncxx::v_noabi::document::view_or_value command);
153
166 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
167 run_command(const client_session& session, bsoncxx::v_noabi::document::view_or_value command);
168
181 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::value)
182 run_command(bsoncxx::v_noabi::document::view_or_value command, uint32_t server_id);
183
205 create_collection(bsoncxx::v_noabi::stdx::string_view name,
206 bsoncxx::v_noabi::document::view_or_value collection_options = {},
208
233 bsoncxx::v_noabi::stdx::string_view name,
234 bsoncxx::v_noabi::document::view_or_value collection_options = {},
236
251 drop(const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>& write_concern =
252 {});
253
270 drop(const client_session& session,
271 const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>& write_concern =
272 {});
273
285 has_collection(bsoncxx::v_noabi::string::view_or_value name) const;
286
299 list_collections(bsoncxx::v_noabi::document::view_or_value filter = {});
300
316 bsoncxx::v_noabi::document::view_or_value filter = {});
317
332 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
333 list_collection_names(bsoncxx::v_noabi::document::view_or_value filter = {});
334
351 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
353 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(const options::gridfs::bucket& options = options::gridfs::bucket()) const;
465
480
494 watch(const client_session& session, const options::change_stream& options = {});
495
514 watch(const pipeline& pipe, const options::change_stream& options = {});
515
533 watch(const client_session& session,
534 const pipeline& pipe,
535 const options::change_stream& options = {});
536
537 private:
538 friend ::mongocxx::v_noabi::client_encryption;
539 friend ::mongocxx::v_noabi::client;
540 friend ::mongocxx::v_noabi::collection;
541
543
544 cursor _aggregate(const client_session* session,
545 const pipeline& pipeline,
546 const options::aggregate& options);
547
550
551 mongocxx::v_noabi::collection _create_collection(
552 const client_session* session,
556
557 cursor _list_collections(const client_session* session,
559
560 std::vector<std::string> _list_collection_names(
562
563 void _drop(
564 const client_session* session,
566
567 change_stream _watch(const client_session* session,
568 const pipeline& pipe,
569 const options::change_stream& options);
570
571 class impl;
572
573 impl& _get_impl();
574 const impl& _get_impl() const;
575
576 std::unique_ptr<impl> _impl;
577};
578
579} // namespace v_noabi
580} // namespace mongocxx
581
583
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:826
A polyfill for std::string_view.
Definition string_view.hpp:436
Class representing a view-or-value variant type for strings.
Definition view_or_value.hpp:41
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:61
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: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.
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={}, const bsoncxx::v_noabi::stdx::optional< write_concern > &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.
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 ...
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:66
Class representing the optional arguments to a MongoDB aggregation operation.
Definition aggregate.hpp:43
Class representing MongoDB change stream options.
Definition change_stream.hpp:38
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:57
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:64
Class representing the server-side requirement for reporting the success of a write operation....
Definition write_concern.hpp:60
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 fwd.hpp:204
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.