MongoDB C++ Driver 4.4.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
30#include <mongocxx/client_bulk_write-fwd.hpp> // IWYU pragma: export
32#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
35#include <mongocxx/options/auto_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
36#include <mongocxx/options/client_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
38#include <mongocxx/pool-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
39
42
44#include <mongocxx/database.hpp>
47#include <mongocxx/options/client_encryption.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
51#include <mongocxx/uri.hpp>
53
55
56namespace mongocxx {
57namespace v_noabi {
58
77class client {
78 private:
79 v1::client _client;
80
81 public:
87 client() noexcept {}
88
92 /* explicit(false) */ client(v1::client client) : _client{std::move(client)} {}
93
102 explicit operator v1::client() && {
103 return std::move(_client);
104 }
105
109 explicit operator v1::client() const& = delete;
110
123 v_noabi::uri const& mongodb_uri,
124 options::client const& options = options::client());
125
130 explicit operator bool() const noexcept {
131 return _client.operator bool();
132 }
133
152
153 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) read_concern_deprecated(v_noabi::read_concern rc);
154
161
180
182 read_preference_deprecated(v_noabi::read_preference rp);
183
193
200
216
217 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) write_concern_deprecated(v_noabi::write_concern wc);
218
224
236 database(bsoncxx::v_noabi::string::view_or_value name) const&;
237
238 v_noabi::database database(bsoncxx::v_noabi::string::view_or_value name) const&& = delete;
239
251 v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) const& {
252 return database(name);
253 }
254
256
273
293
313 list_databases(bsoncxx::v_noabi::document::view_or_value const opts) const;
314
337 list_databases(v_noabi::client_session const& session, bsoncxx::v_noabi::document::view_or_value const opts) const;
338
353 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(std::vector<std::string>)
354 list_database_names(bsoncxx::v_noabi::document::view_or_value const filter = {}) const;
355
373 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(std::vector<std::string>)
375 v_noabi::client_session const& session,
376 bsoncxx::v_noabi::document::view_or_value const filter = {}) const;
377
390
407
426
447
468 v_noabi::client_session const& session,
469 v_noabi::pipeline const& pipe,
470 v_noabi::options::change_stream const& options = {});
471
477
480
497
498 class internal;
499
500 private:
502 v_noabi::client_session const* session,
503 v_noabi::pipeline const& pipe,
505};
506
507} // namespace v_noabi
508} // namespace mongocxx
509
510namespace mongocxx {
511namespace v_noabi {
512
517 return {std::move(v)};
518}
519
524 return v1::client{std::move(v)};
525}
526
527} // namespace v_noabi
528} // namespace mongocxx
529
531
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:87
A list of bulk write operations. Unlike mongocxx::v1::bulk_write, this supports writes across more th...
Definition client_bulk_write.hpp:58
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:77
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.
v1::client_bulk_write create_bulk_write()
Return a new client-level bulk write operation for use with this 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:87
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:251
v1::client_bulk_write create_bulk_write(v_noabi::client_session &session)
Return a new client-level bulk write operation for use with this client.
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:92
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
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
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::client_bulk_write.
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.