MongoDB C++ Driver  mongocxx-3.4.0
Classes | 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>

Classes

class  entry
 An entry is a handle on a client object acquired via the pool. More...
 

Public Member Functions

 pool (const uri &mongodb_uri=mongocxx::uri(), const options::pool &options=options::pool())
 Creates a pool associated with a connection string. More...
 
 ~pool ()
 Destroys a pool.
 
entry acquire ()
 Acquires a client from the pool. More...
 
stdx::optional< entrytry_acquire ()
 Acquires a client from the pool. More...
 

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
https://docs.mongodb.com/master/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 per server to monitor the topology of the replica set, all of which are shared between the client objects created by the pool. A standalone client will instead "stop the world" every 60 seconds to check the status of the cluster. Because of this, if multiple threads are available, a connection pool should be used even if the application itself is single-threaded.

Constructor & Destructor Documentation

◆ pool()

mongocxx::pool::pool ( const uri mongodb_uri = mongocxx::uri(),
const options::pool options = options::pool() 
)
explicit

Creates a pool associated with a connection string.

Parameters
mongodb_uriA MongoDB URI representing the connection parameters
optionsOptions to use when connecting to the MongoDB deployment.
Exceptions
mongocxx::exceptionif invalid options are provided (whether from the URI or provided client options).

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: