MongoDB C++ Driver mongocxx-3.7.0
Loading...
Searching...
No Matches
client.hpp
1// Copyright 2014-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
19#include <mongocxx/client_session.hpp>
20#include <mongocxx/database.hpp>
21#include <mongocxx/options/client.hpp>
22#include <mongocxx/options/client_encryption.hpp>
23#include <mongocxx/options/client_session.hpp>
24#include <mongocxx/read_concern.hpp>
25#include <mongocxx/read_preference.hpp>
26#include <mongocxx/stdx.hpp>
27#include <mongocxx/uri.hpp>
28#include <mongocxx/write_concern.hpp>
29
30#include <mongocxx/config/prelude.hpp>
31
35namespace mongocxx {
36MONGOCXX_INLINE_NAMESPACE_BEGIN
37
38class client_session;
39
58class MONGOCXX_API client {
59 public:
65 client() noexcept;
66
78 client(const class uri& mongodb_uri, const options::client& options = options::client());
79
83 client(client&&) noexcept;
84
88 client& operator=(client&&) noexcept;
89
94
99 explicit operator bool() const noexcept;
100
117 MONGOCXX_DEPRECATED void read_concern(class read_concern rc);
118 void read_concern_deprecated(class read_concern rc);
119
126
143 MONGOCXX_DEPRECATED void read_preference(class read_preference rp);
144 void read_preference_deprecated(class read_preference rp);
145
154
160 class uri uri() const;
161
176 MONGOCXX_DEPRECATED void write_concern(class write_concern wc);
177 void write_concern_deprecated(class write_concern wc);
178
184
195 class database database(bsoncxx::string::view_or_value name) const&;
196 class database database(bsoncxx::string::view_or_value name) const&& = delete;
197
209 MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&;
210 MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&& = delete;
211
227 cursor list_databases() const;
228
245 cursor list_databases(const client_session& session) const;
246
263 cursor list_databases(const bsoncxx::document::view_or_value opts) const;
264
278 std::vector<std::string> list_database_names(
279 const bsoncxx::document::view_or_value filter = {}) const;
280
284
295
311
323 change_stream watch(const client_session& session, const options::change_stream& options = {});
324
341 change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
342
359 const pipeline& pipe,
360 const options::change_stream& options = {});
361
365
381 void reset();
382
383 private:
384 friend class collection;
385 friend class database;
386 friend class pool;
387 friend class client_session;
388 friend class options::auto_encryption;
389 friend class options::client_encryption;
390
391 MONGOCXX_PRIVATE explicit client(void* implementation);
392
393 MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
394 const pipeline& pipe,
395 const options::change_stream& options);
396
397 class MONGOCXX_PRIVATE impl;
398
399 MONGOCXX_PRIVATE impl& _get_impl();
400 MONGOCXX_PRIVATE const impl& _get_impl() const;
401
402 std::unique_ptr<impl> _impl;
403};
404
406 return database(name);
407}
408
409MONGOCXX_INLINE_NAMESPACE_END
410} // namespace mongocxx
411
412#include <mongocxx/config/postlude.hpp>
Class representing a view-or-value variant type for strings.
Definition view_or_value.hpp:36
Class representing a MongoDB change stream.
Definition change_stream.hpp:34
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:40
Class representing a client connection to MongoDB.
Definition client.hpp:58
void reset()
Prevents resource cleanup in the child process from interfering with the parent process after forking...
client_session start_session(const options::client_session &options={})
Create a client session for a sequence of operations.
change_stream watch(const options::change_stream &options={})
Gets a change stream on this client with an empty pipeline.
client() noexcept
Default constructs a new client.
class database operator[](bsoncxx::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:405
change_stream watch(const client_session &session, const options::change_stream &options={})
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this client.
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this client.
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:83
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:36
Class representing a MongoDB database.
Definition database.hpp:43
Class representing options for automatic client-side encryption.
Definition auto_encryption.hpp:36
Class representing MongoDB change stream options.
Definition change_stream.hpp:39
Class representing options for the object managing explicit client-side encryption.
Definition client_encryption.hpp:36
Class representing the optional arguments to mongocxx::client::start_session.
Definition client_session.hpp:30
Class representing a MongoDB aggregation pipeline.
Definition pipeline.hpp:38
A pool of client objects associated with a MongoDB deployment.
Definition pool.hpp:47
A class to represent the read concern.
Definition read_concern.hpp:54
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:63
Class representing a MongoDB connection string URI.
Definition uri.hpp:43
Class representing the server-side requirement for reporting the success of a write operation.
Definition write_concern.hpp:56
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
Top level namespace for the MongoDB C++ driver.
Definition bulk_write.hpp:24