Github   Telegram
No Matches
Public Member Functions | List of all members
storages::mongo::Pool Class Reference

MongoDB client pool. More...

#include <userver/storages/mongo/pool.hpp>

Public Member Functions

 Pool (std::string id, const std::string &uri, const PoolConfig &pool_config, clients::dns::Resolver *dns_resolver, const Config &mongo_config)
bool HasCollection (const std::string &name) const
 Checks whether a collection exists.
Collection GetCollection (std::string name) const
 Returns a handle for the specified collection.
formats::json::Value GetStatistics () const
 Returns pool statistics JSON.
formats::json::Value GetVerboseStatistics () const
 Returns verbose pool statistics JSON (with separate metrics for ops/RP/WC)
void SetConfig (const Config &config)

Detailed Description

MongoDB client pool.

Use constructor only for tests, in production the pool should be retrieved from the components via components::Mongo::GetPool() or components::MultiMongo::GetPool().

Example usage:

inline void SampleMongoPool(storages::mongo::Pool pool) {
auto in_coll = pool.GetCollection("aggregate_in");
formats::bson::MakeDoc("_id", 1, "x", 0),
formats::bson::MakeDoc("_id", 2, "x", 1),
formats::bson::MakeDoc("_id", 3, "x", 2),
auto cursor = in_coll.Aggregate(
MakeArray(MakeDoc("$match", MakeDoc("_id", MakeDoc("$gte", 2))),
MakeDoc("$addFields", MakeDoc("check", true)),
MakeDoc("$out", "aggregate_out")),
auto out_coll = pool.GetCollection("aggregate_out");
EXPECT_EQ(2, out_coll.CountApprox());
for (const auto& doc : out_coll.Find({})) {
EXPECT_EQ(doc["_id"].As<int>(), doc["x"].As<int>() + 1);

Definition at line 36 of file pool.hpp.

Constructor & Destructor Documentation

◆ Pool()

storages::mongo::Pool::Pool ( std::string  id,
const std::string &  uri,
const PoolConfig pool_config,
clients::dns::Resolver dns_resolver,
const Config &  mongo_config 

Client pool constructor

idpool identificaton string
uridatabase connection string
configpool configuration

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