MongoDB C++ Driver  mongocxx-3.9.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
32 namespace mongocxx {
33 inline namespace v_noabi {
34 class client_session;
35 
54 class MONGOCXX_API client {
55  public:
61  client() noexcept;
62 
74  client(const class uri& mongodb_uri, const options::client& options = options::client());
75 
79  client(client&&) noexcept;
80 
84  client& operator=(client&&) noexcept;
85 
89  ~client();
90 
95  explicit operator bool() const noexcept;
96 
113  MONGOCXX_DEPRECATED void read_concern(class read_concern rc);
114  void read_concern_deprecated(class read_concern rc);
115 
121  class read_concern read_concern() const;
122 
139  MONGOCXX_DEPRECATED void read_preference(class read_preference rp);
140  void read_preference_deprecated(class read_preference rp);
141 
149  class read_preference read_preference() const;
150 
156  class uri uri() const;
157 
172  MONGOCXX_DEPRECATED void write_concern(class write_concern wc);
173  void write_concern_deprecated(class write_concern wc);
174 
179  class write_concern write_concern() const;
180 
191  class database database(bsoncxx::string::view_or_value name) const&;
192  class database database(bsoncxx::string::view_or_value name) const&& = delete;
193 
205  MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&;
206  MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&& = delete;
207 
223  cursor list_databases() const;
224 
241  cursor list_databases(const client_session& session) const;
242 
259  cursor list_databases(const bsoncxx::document::view_or_value opts) const;
260 
280  cursor list_databases(const client_session& session,
281  const bsoncxx::document::view_or_value opts) const;
282 
296  std::vector<std::string> list_database_names(
297  const bsoncxx::document::view_or_value filter = {}) const;
298 
315  std::vector<std::string> list_database_names(
316  const client_session& session, const bsoncxx::document::view_or_value filter = {}) const;
317 
321 
332 
348 
360  change_stream watch(const client_session& session, const options::change_stream& options = {});
361 
378  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
379 
396  const pipeline& pipe,
397  const options::change_stream& options = {});
398 
402 
418  void reset();
419 
420  private:
421  friend class collection;
422  friend class database;
423  friend class pool;
424  friend class client_session;
425  friend class options::auto_encryption;
426  friend class options::client_encryption;
427 
428  MONGOCXX_PRIVATE explicit client(void* implementation);
429 
430  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
431  const pipeline& pipe,
432  const options::change_stream& options);
433 
434  class MONGOCXX_PRIVATE impl;
435 
436  MONGOCXX_PRIVATE impl& _get_impl();
437  MONGOCXX_PRIVATE const impl& _get_impl() const;
438 
439  std::unique_ptr<impl> _impl;
440 };
441 
442 MONGOCXX_INLINE database client::operator[](bsoncxx::string::view_or_value name) const& {
443  return database(name);
444 }
445 
446 } // namespace v_noabi
447 } // namespace mongocxx
448 
449 #include <mongocxx/config/postlude.hpp>
Class representing a MongoDB change stream.
Definition: change_stream.hpp:33
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:54
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.
change_stream watch(const client_session &session, const options::change_stream &options={})
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:442
client() noexcept
Default constructs a new client.
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this client.
void reset()
Prevents resource cleanup in the child process from interfering with the parent process after forking...
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.
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:85
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:35
Class representing MongoDB change stream options.
Definition: change_stream.hpp:38
Class representing options for the object managing explicit client-side encryption.
Definition: client_encryption.hpp:35
Class representing the optional arguments to mongocxx::client::start_session.
Definition: client_session.hpp:32
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:37
A pool of client objects associated with a MongoDB deployment.
Definition: pool.hpp:46
A class to represent the read concern.
Definition: read_concern.hpp:57
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:67
Class representing a MongoDB connection string URI.
Definition: uri.hpp:42
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:59
The top-level namespace for bsoncxx library entities.
Definition: element.hpp:24
The top-level namespace for mongocxx library entities.
Definition: bulk_write.hpp:24