MongoDB C++ Driver
mongocxx-3.0.0
|
A pool of client
objects associated with a MongoDB deployment.
More...
#include <pool.hpp>
Public Types | |
using | entry = std::unique_ptr< client, std::function< void(client *)>> |
An entry is a handle on a client object acquired via the pool. More... | |
Public Member Functions | |
pool (const uri &mongodb_uri=mongocxx::uri(), stdx::optional< options::ssl > ssl_options=stdx::nullopt) | |
Creates a pool associated with a connection string. More... | |
~pool () | |
Destroys a pool. | |
entry | acquire () |
Acquires a client from the pool. More... | |
stdx::optional< entry > | try_acquire () |
Acquires a client from the pool. More... | |
A pool of client
objects associated with a MongoDB deployment.
For interoperability with other MongoDB drivers, the minimum and maximum number of connections in the pool is configured using the 'minPoolSize' and 'maxPoolSize' connection string options.
client
objects. The pool will use a single background thread used to monitor the topology of the replica set that is shared between all the client objects it creates. Each standalone client, however, will start its own background thread, leading to many redundant threads and network operations.As a client
is not thread safe, the pool
should be preferred in multithreaded programs as it can safely be shared across threads.
using mongocxx::pool::entry = std::unique_ptr<client, std::function<void(client*)>> |
An entry is a handle on a client
object acquired via the pool.
mongocxx::pool::pool | ( | const uri & | mongodb_uri = mongocxx::uri() , |
stdx::optional< options::ssl > | ssl_options = stdx::nullopt |
||
) |
Creates a pool associated with a connection string.
mongodb_uri | A MongoDB URI representing the connection parameters |
ssl_options | Optional SSL options to use when connecting to the MongoDB deployment. |
entry mongocxx::pool::acquire | ( | ) |
Acquires a client from the pool.
The calling thread will block until a connection is available.
stdx::optional<entry> mongocxx::pool::try_acquire | ( | ) |
Acquires a client from the pool.
This method will return immediately, but may return a disengaged optional if a client is not available.