MongoDB C++ Driver mongocxx-3.0.3
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
mongocxx::pool Class Reference

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.
 

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.
 
 ~pool ()
 Destroys a pool.
 
entry acquire ()
 Acquires a client from the pool.
 
stdx::optional< entrytry_acquire ()
 Acquires a client from the pool.
 

Detailed Description

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.

See also
http://docs.mongodb.org/manual/reference/connection-string/#connection-string-options
Remarks
When connecting to a replica set, it is much more efficient to use a pool as opposed to manually constructing 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.

Member Typedef Documentation

◆ entry

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.

Note
The lifetime of any entry object must be a subset of the pool object from which it was acquired.

Constructor & Destructor Documentation

◆ 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.

Parameters
mongodb_uriA MongoDB URI representing the connection parameters
ssl_optionsOptional SSL options to use when connecting to the MongoDB deployment.
Exceptions
mongocxx::exceptionif SSL is enabled and ssl_options are invalid, or if SSL is not enabled and ssl_options is engaged.

Member Function Documentation

◆ acquire()

entry mongocxx::pool::acquire ( )

Acquires a client from the pool.

The calling thread will block until a connection is available.

◆ try_acquire()

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.


The documentation for this class was generated from the following file: