MongoDB C++ Driver 4.5.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
23
24#include <mongocxx/v1/client.hpp> // IWYU pragma: export
25
26#include <list> // IWYU pragma: keep: backward compatibility, to be removed.
27#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
28#include <string>
29#include <utility>
30#include <vector>
31
33#include <mongocxx/client_bulk_write-fwd.hpp> // IWYU pragma: export
35#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
38#include <mongocxx/options/auto_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
39#include <mongocxx/options/client_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
41#include <mongocxx/pool-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
42
45
47#include <mongocxx/database.hpp>
50#include <mongocxx/options/client_encryption.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
54#include <mongocxx/uri.hpp>
56
58
59namespace mongocxx {
60namespace v_noabi {
61
80class client {
81 private:
82 v1::client _client;
83
84 public:
90 client() noexcept {}
91
95 /* explicit(false) */ client(v1::client client) : _client{std::move(client)} {}
96
105 explicit operator v1::client() && {
106 return std::move(_client);
107 }
108
112 explicit operator v1::client() const& = delete;
113
126 v_noabi::uri const& mongodb_uri,
127 options::client const& options = options::client());
128
133 explicit operator bool() const noexcept {
134 return _client.operator bool();
135 }
136
155
156 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) read_concern_deprecated(v_noabi::read_concern rc);
157
164
183
185 read_preference_deprecated(v_noabi::read_preference rp);
186
196
203
219
220 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) write_concern_deprecated(v_noabi::write_concern wc);
221
227
239 database(bsoncxx::v_noabi::string::view_or_value name) const&;
240
241 v_noabi::database database(bsoncxx::v_noabi::string::view_or_value name) const&& = delete;
242
254 v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) const& {
255 return database(name);
256 }
257
259
276
296
316 list_databases(bsoncxx::v_noabi::document::view_or_value const opts) const;
317
340 list_databases(v_noabi::client_session const& session, bsoncxx::v_noabi::document::view_or_value const opts) const;
341
356 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(std::vector<std::string>)
357 list_database_names(bsoncxx::v_noabi::document::view_or_value const filter = {}) const;
358
376 MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(std::vector<std::string>)
378 v_noabi::client_session const& session,
379 bsoncxx::v_noabi::document::view_or_value const filter = {}) const;
380
393
410
429
450
471 v_noabi::client_session const& session,
472 v_noabi::pipeline const& pipe,
473 v_noabi::options::change_stream const& options = {});
474
480
483
506
523
524 class internal;
525
526 private:
528 v_noabi::client_session const* session,
529 v_noabi::pipeline const& pipe,
531};
532
533} // namespace v_noabi
534} // namespace mongocxx
535
536namespace mongocxx {
537namespace v_noabi {
538
543 return {std::move(v)};
544}
545
550 return v1::client{std::move(v)};
551}
552
553} // namespace v_noabi
554} // namespace mongocxx
555
557
Declares mongocxx::v_noabi::options::auto_encryption.
A polyfill for std::optional<T>.
Definition optional.hpp:799
A polyfill for std::string_view.
Definition string_view.hpp:412
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:90
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:80
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.
void append_metadata(bsoncxx::v1::stdx::string_view name, bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > version={}, bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > platform={})
Append client metadata to the handshake command sent as part of the initial connection handshake.
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:90
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:254
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:95
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.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
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.