MongoDB C++ Driver current
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
284 cursor list_databases(const client_session& session,
285 const bsoncxx::document::view_or_value opts) const;
286
300 std::vector<std::string> list_database_names(
301 const bsoncxx::document::view_or_value filter = {}) const;
302
319 std::vector<std::string> list_database_names(
320 const client_session& session, const bsoncxx::document::view_or_value filter = {}) const;
321
325
336
352
364 change_stream watch(const client_session& session, const options::change_stream& options = {});
365
382 change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
383
400 const pipeline& pipe,
401 const options::change_stream& options = {});
402
406
422 void reset();
423
424 private:
425 friend class collection;
426 friend class database;
427 friend class pool;
428 friend class client_session;
429 friend class options::auto_encryption;
430 friend class options::client_encryption;
431
432 MONGOCXX_PRIVATE explicit client(void* implementation);
433
434 MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
435 const pipeline& pipe,
436 const options::change_stream& options);
437
438 class MONGOCXX_PRIVATE impl;
439
440 MONGOCXX_PRIVATE impl& _get_impl();
441 MONGOCXX_PRIVATE const impl& _get_impl() const;
442
443 std::unique_ptr<impl> _impl;
444};
445
447 return database(name);
448}
449
450MONGOCXX_INLINE_NAMESPACE_END
451} // namespace mongocxx
452
453#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.
std::vector< std::string > list_database_names(const client_session &session, const bsoncxx::document::view_or_value filter={}) const
Queries the MongoDB server for a list of known databases.
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:446
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:84
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:44
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