class mongodb_pool
{
public:
...
void setup(unique_ptr<mongocxx::pool> pool);
mongocxx::pool::entry acquire();
private:
unique_ptr<mongocxx::pool> _pool = nullptr;
};
void mongodb_pool::setup(unique_ptr<mongocxx::pool> pool)
{ _pool = move(pool);
}
mongocxx::pool::entry mongodb_pool::acquire()
{ return _pool->acquire();
}class mongodb
{
public:
...
bool has_session(string name);
void create_session(string name, string connection_string);
mongocxx::client_session session(string name);
...
vector<string> database_names(mongocxx::client_session &session);
mongocxx::database database(mongocxx::client_session &session, string database_name);
...
private:
map<string, pool::mongodb_pool> _pools;
...
};
bool mongodb::has_session(string name)
{ return (_pools.find(name) != _pools.end());
}
void mongodb::create_session(string name, string connection_string)
{
if (!has_session(name))
{
pool::mongodb_pool temp;
temp.setup(bsoncxx::stdx::make_unique<mongocxx::pool>(move(mongocxx::uri{connection_string})));
_pools[name] = move(temp);
}
}
mongocxx::client_session mongodb::session(string name)
{
auto client = _pools[name].acquire();
return (*client).start_session();
}
vector<string> mongodb::database_names(mongocxx::client_session &session)
{
vector<string> result;
mongocxx::cursor cursor = session.client().list_databases(session);
for (const bsoncxx::document::view doc : cursor)
{ result.push_back(doc["name"].get_utf8().value.to_string());
}
sort(result.begin(), result.end());
return result;
}
mongocxx::database mongodb::database(mongocxx::client_session &session, string database_name)
{
return session.client().database(database_name);
}if (!mongodb.has_session("test"))
{
string session_uri("mongodb://127.0.0.1:27017");
mongodb.create_session("test", session_uri);
}
mongocxx::client_session session = mongodb.session("test");
vector<string> db_names = mongodb.database_names(session);
for (unsigned int i = 0; i < db_names.size(); i++)
{
cout << db_names[i] << endl;
}--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/54200a85-ca37-4336-abb3-4a0de57f0322%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAHX05qF2%3DXb2Qyo7CbBGEG%2BPQP-vYLn7o%3DFmTF7sE%2B%3DOkdqLvw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CACU-GDd0mjRbTvNOPSb5Dn95AN9WcCGJDmmyugkis5zpH5pinQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAHX05qGKRXk0iHytayomtjyQu644AezhH8dsiMnciWX0g57gtg%40mail.gmail.com.
Good evening, Andrew
I'll have to go through the valgrind documentation and logs later. I hope that it will help.
I have to, for the moment, abandon the pool usage idea and just use a single instance of client.I'm now focusing my attention to the rest of the code, to ensure that everything works as expected, and I've already picked up a problem with "update_one" and I've created a separate post for the problem.