MongoDB C++ Driver  mongocxx-3.10.2
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-fwd.hpp>
20 #include <mongocxx/client_session-fwd.hpp>
21 #include <mongocxx/collection-fwd.hpp>
22 #include <mongocxx/database-fwd.hpp>
23 #include <mongocxx/options/auto_encryption-fwd.hpp>
24 #include <mongocxx/options/client_encryption-fwd.hpp>
25 #include <mongocxx/pool-fwd.hpp>
26 
27 #include <mongocxx/client_session.hpp>
28 #include <mongocxx/database.hpp>
29 #include <mongocxx/options/client.hpp>
30 #include <mongocxx/options/client_encryption.hpp>
31 #include <mongocxx/options/client_session.hpp>
32 #include <mongocxx/read_concern.hpp>
33 #include <mongocxx/read_preference.hpp>
34 #include <mongocxx/stdx.hpp>
35 #include <mongocxx/uri.hpp>
36 #include <mongocxx/write_concern.hpp>
37 
38 #include <mongocxx/config/prelude.hpp>
39 
40 namespace mongocxx {
41 namespace v_noabi {
42 
61 class client {
62  public:
68  client() noexcept;
69 
81  client(const mongocxx::v_noabi::uri& mongodb_uri,
82  const options::client& options = options::client());
83 
87  client(client&&) noexcept;
88 
92  client& operator=(client&&) noexcept;
93 
97  ~client();
98 
103  explicit operator bool() const noexcept;
104 
121  MONGOCXX_DEPRECATED void read_concern(mongocxx::v_noabi::read_concern rc);
122  void read_concern_deprecated(mongocxx::v_noabi::read_concern rc);
123 
129  mongocxx::v_noabi::read_concern read_concern() const;
130 
147  MONGOCXX_DEPRECATED void read_preference(mongocxx::v_noabi::read_preference rp);
148  void read_preference_deprecated(mongocxx::v_noabi::read_preference rp);
149 
158 
164  mongocxx::v_noabi::uri uri() const;
165 
180  MONGOCXX_DEPRECATED void write_concern(mongocxx::v_noabi::write_concern wc);
181  void write_concern_deprecated(mongocxx::v_noabi::write_concern wc);
182 
188 
199  mongocxx::v_noabi::database database(bsoncxx::v_noabi::string::view_or_value name) const&;
200  mongocxx::v_noabi::database database(bsoncxx::v_noabi::string::view_or_value name) const&& =
201  delete;
202 
214  MONGOCXX_INLINE mongocxx::v_noabi::database operator[](
215  bsoncxx::v_noabi::string::view_or_value name) const&;
216  MONGOCXX_INLINE mongocxx::v_noabi::database operator[](
217  bsoncxx::v_noabi::string::view_or_value name) const&& = delete;
218 
236 
254  cursor list_databases(const client_session& session) const;
255 
273  cursor list_databases(const bsoncxx::v_noabi::document::view_or_value opts) const;
274 
296  const bsoncxx::v_noabi::document::view_or_value opts) const;
297 
311  std::vector<std::string> list_database_names(
312  const bsoncxx::v_noabi::document::view_or_value filter = {}) const;
313 
330  std::vector<std::string> list_database_names(
331  const client_session& session,
332  const bsoncxx::v_noabi::document::view_or_value filter = {}) const;
333 
337 
349 
365 
377  change_stream watch(const client_session& session, const options::change_stream& options = {});
378 
395  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
396 
413  const pipeline& pipe,
414  const options::change_stream& options = {});
415 
419 
435  void reset();
436 
437  private:
438  friend ::mongocxx::v_noabi::client_session;
439  friend ::mongocxx::v_noabi::collection;
440  friend ::mongocxx::v_noabi::database;
441  friend ::mongocxx::v_noabi::options::auto_encryption;
442  friend ::mongocxx::v_noabi::options::client_encryption;
443  friend ::mongocxx::v_noabi::pool;
444 
445  MONGOCXX_PRIVATE explicit client(void* implementation);
446 
447  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
448  const pipeline& pipe,
449  const options::change_stream& options);
450 
451  class MONGOCXX_PRIVATE impl;
452 
453  MONGOCXX_PRIVATE impl& _get_impl();
454  MONGOCXX_PRIVATE const impl& _get_impl() const;
455 
456  std::unique_ptr<impl> _impl;
457 };
458 
461  return database(name);
462 }
463 
464 } // namespace v_noabi
465 } // namespace mongocxx
466 
467 #include <mongocxx/config/postlude.hpp>
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:38
Class representing a MongoDB change stream.
Definition: change_stream.hpp:35
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition: client_session.hpp:47
Class representing a client connection to MongoDB.
Definition: client.hpp:61
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.
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:459
std::vector< std::string > list_database_names(const client_session &session, const bsoncxx::v_noabi::document::view_or_value filter={}) const
Queries the MongoDB server for a list of known databases.
change_stream watch(const client_session &session, const options::change_stream &options={})
std::vector< std::string > list_database_names(const bsoncxx::v_noabi::document::view_or_value filter={}) const
Queries the MongoDB server for a list of known databases.
client() noexcept
Default constructs a new client.
cursor list_databases() const
Enumerates the databases in the 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...
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this client.
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:42
Class representing a MongoDB database.
Definition: database.hpp:46
Class representing MongoDB change stream options.
Definition: change_stream.hpp:39
Class representing the optional arguments to mongocxx::v_noabi::client::start_session.
Definition: client_session.hpp:33
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:39
A class to represent the read concern.
Definition: read_concern.hpp:56
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:47
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:58
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19