blob: f03cece44f8c5a2a2e31beb4bdad1b037659ecd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#ifndef MongoAccess_H_
#define MongoAccess_H_
#include <cstdlib>
#include <memory>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/stdx/string_view.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/pool.hpp>
#include <mongocxx/uri.hpp>
#include <iostream>
class mongo_access {
public:
mongo_access ();
~mongo_access ();
void configure(mongocxx::uri uri);
using connection = mongocxx::pool::entry;
connection get_connection() {
return _pool->acquire();
}
bsoncxx::stdx::optional<connection> try_get_connection() {
return _pool->try_acquire();
}
private:
std::unique_ptr<mongocxx::instance> _instance = nullptr;
std::unique_ptr<mongocxx::pool> _pool = nullptr;
};
#endif
|