MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <memory>
18#include <string>
19
26#include <mongocxx/pool-fwd.hpp>
27
29#include <mongocxx/database.hpp>
35#include <mongocxx/uri.hpp>
37
39
40namespace mongocxx {
41namespace v_noabi {
42
61class client {
62 public:
69
82 client(mongocxx::v_noabi::uri const& mongodb_uri, options::client const& options = options::client());
83
88
92 MONGOCXX_ABI_EXPORT_CDECL(client&) operator=(client&&) noexcept;
93
98
99 client(client const&) = delete;
100 client& operator=(client const&) = delete;
101
106 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
107
126
127 MONGOCXX_ABI_EXPORT_CDECL(void) read_concern_deprecated(mongocxx::v_noabi::read_concern rc);
128
135
154
156 read_preference_deprecated(mongocxx::v_noabi::read_preference rp);
157
167
174
190
191 MONGOCXX_ABI_EXPORT_CDECL(void) write_concern_deprecated(mongocxx::v_noabi::write_concern wc);
192
198
210 database(bsoncxx::v_noabi::string::view_or_value name) const&;
211
212 mongocxx::v_noabi::database database(bsoncxx::v_noabi::string::view_or_value name) const&& = delete;
213
225 mongocxx::v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) const& {
226 return database(name);
227 }
228
246
266
286 list_databases(bsoncxx::v_noabi::document::view_or_value const opts) const;
287
310 list_databases(client_session const& session, bsoncxx::v_noabi::document::view_or_value const opts) const;
311
326 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
327 list_database_names(bsoncxx::v_noabi::document::view_or_value const filter = {}) const;
328
346 MONGOCXX_ABI_EXPORT_CDECL(std::vector<std::string>)
347 list_database_names(client_session const& session, bsoncxx::v_noabi::document::view_or_value const filter = {})
348 const;
349
362
378
396 watch(client_session const& session, options::change_stream const& options = {});
397
417 watch(pipeline const& pipe, options::change_stream const& options = {});
418
438 watch(client_session const& session, pipeline const& pipe, options::change_stream const& options = {});
439
456
457 private:
458 friend ::mongocxx::v_noabi::client_session;
459 friend ::mongocxx::v_noabi::collection;
460 friend ::mongocxx::v_noabi::database;
461 friend ::mongocxx::v_noabi::options::auto_encryption;
462 friend ::mongocxx::v_noabi::options::client_encryption;
463 friend ::mongocxx::v_noabi::pool;
464
465 explicit client(void* implementation);
466
467 change_stream _watch(client_session const* session, pipeline const& pipe, options::change_stream const& options);
468
469 class impl;
470
471 impl& _get_impl();
472 impl const& _get_impl() const;
473
474 std::unique_ptr<impl> _impl;
475};
476
477} // namespace v_noabi
478} // namespace mongocxx
479
481
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...
A MongoDB change stream.
Definition change_stream.hpp:35
Supports MongoDB client session operations.
Definition client_session.hpp:50
mongocxx::v_noabi::uri uri() const
Returns the current uri for this client.
mongocxx::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:225
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.
void read_concern(mongocxx::v_noabi::read_concern rc)
Sets the read concern for this client.
client() noexcept
Default constructs a new client. The client is not connected and is equivalent to the state of a move...
client_session start_session(options::client_session const &options={})
Create a client session for a sequence of operations.
void write_concern(mongocxx::v_noabi::write_concern wc)
Sets the write concern for this client.
void read_preference(mongocxx::v_noabi::read_preference rp)
Sets the read preference for this client.
cursor list_databases() const
Enumerates the databases in the client.
void reset()
Prevents resource cleanup in the child process from interfering with the parent process after forking...
cursor list_databases(client_session const &session) const
Enumerates the databases in the client.
mongocxx::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.
change_stream watch(options::change_stream const &options={})
Get a change stream on this client with an empty pipeline.
A cursor over the documents returned by a query to a MongoDB server.
Definition cursor.hpp:42
A MongoDB database.
Definition database.hpp:46
Used by change streams.
Definition change_stream.hpp:38
A MongoDB aggregation pipeline.
Definition pipeline.hpp:39
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::database.
Provides mongocxx::v_noabi::database.
#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.
The top-level namespace within which all mongocxx library entities are declared.
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::pool.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::read_preference.
Provides mongocxx::v_noabi::uri.
Provides mongocxx::v_noabi::write_concern.