MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
client.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/client-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/client.hpp> // IWYU pragma: export
22
23#include <list> // IWYU pragma: keep: backward compatibility, to be removed.
24#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
25#include <string>
26#include <utility>
27#include <vector>
28
31#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
34#include <mongocxx/options/auto_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
35#include <mongocxx/options/client_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
37#include <mongocxx/pool-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
38
41
43#include <mongocxx/database.hpp>
46#include <mongocxx/options/client_encryption.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
50#include <mongocxx/uri.hpp>
52
54
55namespace mongocxx {
56namespace v_noabi {
57
76class client {
77 private:
78 v1::client _client;
79
80 public:
86 client() noexcept {}
87
91 /* explicit(false) */ client(v1::client client) : _client{std::move(client)} {}
92
101 explicit operator v1::client() && {
102 return std::move(_client);
103 }
104
108 explicit operator v1::client() const& = delete;
109
122 v_noabi::uri const& mongodb_uri,
123 options::client const& options = options::client());
124
129 explicit operator bool() const noexcept {
130 return _client.operator bool();
131 }
132
151
152 MONGOCXX_ABI_EXPORT_CDECL(void) read_concern_deprecated(v_noabi::read_concern rc);
153
160
179
181 read_preference_deprecated(v_noabi::read_preference rp);
182
192
199
215
216 MONGOCXX_ABI_EXPORT_CDECL(void) write_concern_deprecated(v_noabi::write_concern wc);
217
223
235 database(bsoncxx::v_noabi::string::view_or_value name) const&;
236
237 v_noabi::database database(bsoncxx::v_noabi::string::view_or_value name) const&& = delete;
238
250 v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) const& {
251 return database(name);
252 }
253
255
272
292
312 list_databases(bsoncxx::v_noabi::document::view_or_value const opts) const;
313
336 list_databases(v_noabi::client_session const& session, bsoncxx::v_noabi::document::view_or_value const opts) const;
337
352 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
353 list_database_names(bsoncxx::v_noabi::document::view_or_value const filter = {}) const;
354
372 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
374 v_noabi::client_session const& session,
375 bsoncxx::v_noabi::document::view_or_value const filter = {}) const;
376
389
405
424
445
466 v_noabi::client_session const& session,
467 v_noabi::pipeline const& pipe,
468 v_noabi::options::change_stream const& options = {});
469
486
487 class internal;
488
489 private:
491 v_noabi::client_session const* session,
492 v_noabi::pipeline const& pipe,
494};
495
496} // namespace v_noabi
497} // namespace mongocxx
498
499namespace mongocxx {
500namespace v_noabi {
501
506 return {std::move(v)};
507}
508
513 return v1::client{std::move(v)};
514}
515
516} // namespace v_noabi
517} // namespace mongocxx
518
520
Declares mongocxx::v_noabi::options::auto_encryption.
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
client() noexcept
Default constructs a new client. The client is not connected and is equivalent to the state of a move...
Definition client.hpp:86
A connection to a MongoDB deployment.
Definition client.hpp:60
A MongoDB change stream.
Definition change_stream.hpp:44
Supports MongoDB client session operations.
Definition client_session.hpp:58
A client connection to a MongoDB server.
Definition client.hpp:76
v_noabi::read_preference read_preference() const
Returns the current read preference for this client.
v_noabi::cursor list_databases() const
Enumerates the databases in the client.
void read_preference(v_noabi::read_preference rp)
Sets the read preference for this client.
v_noabi::write_concern write_concern() const
Returns the current write concern for this client.
std::vector< std::string > list_database_names(bsoncxx::v_noabi::document::view_or_value const filter={}) const
Queries the MongoDB server for a list of known databases.
v_noabi::change_stream watch(v_noabi::options::change_stream const &options={})
Get a change stream on this client with an empty pipeline.
v_noabi::cursor list_databases(v_noabi::client_session const &session) const
Enumerates the databases in the client.
v_noabi::uri uri() const
Returns the current uri for this client.
client() noexcept
Default constructs a new client. The client is not connected and is equivalent to the state of a move...
Definition client.hpp:86
v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) const &
Allows the syntax client["db_name"] as a convenient shorthand for the client::database() method by im...
Definition client.hpp:250
void read_concern(v_noabi::read_concern rc)
Sets the read concern for this client.
void write_concern(v_noabi::write_concern wc)
Sets the write concern for this client.
v_noabi::read_concern read_concern() const
Returns the current read concern for this client.
client(v1::client client)
Construct with the mongocxx::v1 equivalent.
Definition client.hpp:91
v_noabi::database database(bsoncxx::v_noabi::string::view_or_value name) const &
Obtains a database that represents a logical grouping of collections on a MongoDB server.
v_noabi::client_session start_session(v_noabi::options::client_session const &options={})
Create a client session for a sequence of operations.
void reset()
Prevents resource cleanup in the child process from interfering with the parent process after forking...
A cursor over the documents returned by a query to a MongoDB server.
Definition cursor.hpp:50
A MongoDB database.
Definition database.hpp:63
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
A MongoDB connection string URI.
Definition uri.hpp:55
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_DEPRECATED
Declares the associated entity as deprecated.
Definition export.hpp:25
#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 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::client.
Declares mongocxx::v_noabi::change_stream.
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::client_session.
Provides mongocxx::v_noabi::client_session.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::cursor.
Declares mongocxx::v_noabi::database.
Provides mongocxx::v_noabi::database.
Provides mongocxx::v_noabi::options::change_stream.
Provides mongocxx::v_noabi::options::client.
Declares mongocxx::v_noabi::options::client_encryption.
Provides mongocxx::v_noabi::options::client_encryption.
Provides mongocxx::v_noabi::options::client_session.
Declares mongocxx::v_noabi::pipeline.
Declares mongocxx::v_noabi::pool.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::read_preference.
Provides mongocxx::v_noabi::uri.
Provides mongocxx::v_noabi::write_concern.