MongoDB C++ Driver  mongocxx-3.6.6
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 
35 namespace mongocxx {
36 MONGOCXX_INLINE_NAMESPACE_BEGIN
37 
38 class client_session;
39 
58 class 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 
93  ~client();
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 
125  class read_concern read_concern() const;
126 
143  MONGOCXX_DEPRECATED void read_preference(class read_preference rp);
144  void read_preference_deprecated(class read_preference rp);
145 
153  class read_preference read_preference() const;
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 
183  class write_concern write_concern() const;
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 filter) 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 
409 MONGOCXX_INLINE_NAMESPACE_END
410 } // namespace mongocxx
411 
412 #include <mongocxx/config/postlude.hpp>
mongocxx::pool
A pool of client objects associated with a MongoDB deployment.
Definition: pool.hpp:47
mongocxx::client::client
client() noexcept
Default constructs a new client.
mongocxx::options::client_encryption
Class representing options for the object managing explicit client-side encryption.
Definition: client_encryption.hpp:36
mongocxx::client::watch
change_stream watch(const options::change_stream &options={})
Gets a change stream on this client with an empty pipeline.
mongocxx::client::watch
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this client.
mongocxx::change_stream
Definition: change_stream.hpp:31
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
mongocxx::client::start_session
client_session start_session(const options::client_session &options={})
Create a client session for a sequence of operations.
mongocxx::write_concern
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:56
mongocxx::options::client_session
Class representing the optional arguments to mongocxx::client::start_session.
Definition: client_session.hpp:30
mongocxx::client::watch
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this client.
mongocxx::client
Class representing a client connection to MongoDB.
Definition: client.hpp:58
mongocxx::read_concern
A class to represent the read concern.
Definition: read_concern.hpp:54
mongocxx::read_preference
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:62
bsoncxx::string::view_or_value
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
mongocxx::client::operator[]
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
mongocxx::client::reset
void reset()
Prevents resource cleanup in the child process from interfering with the parent process after forking...
mongocxx::uri
Class representing a MongoDB connection string URI.
Definition: uri.hpp:43
mongocxx::client::watch
change_stream watch(const client_session &session, const options::change_stream &options={})
mongocxx::options::auto_encryption
Class representing options for automatic client-side encryption.
Definition: auto_encryption.hpp:36
mongocxx::pipeline
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:38
mongocxx::options::change_stream
Definition: change_stream.hpp:35
mongocxx::client_session
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:39
mongocxx::database
Class representing a MongoDB database.
Definition: database.hpp:43
mongocxx::collection
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:81
mongocxx::cursor
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36