aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-08-08 13:48:39 +0200
committerneodarz <neodarz@neodarz.net>2019-08-08 13:48:39 +0200
commit4671f4a46bf9aca39f0a09d0bec115a7f8913614 (patch)
tree8ed81cc3fcd0a656340fdfe4ae422ce22c5738d2 /api
parent889093b2ea55969e8c2920652bdf36bfa3a04cc2 (diff)
downloadumosapicpp-4671f4a46bf9aca39f0a09d0bec115a7f8913614.tar.xz
umosapicpp-4671f4a46bf9aca39f0a09d0bec115a7f8913614.zip
Implement mongocxx pool connection
Diffstat (limited to '')
-rw-r--r--api/umosapi.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/api/umosapi.cpp b/api/umosapi.cpp
index 65f28d2..de2a2c3 100644
--- a/api/umosapi.cpp
+++ b/api/umosapi.cpp
@@ -14,6 +14,9 @@
#include "umosapi.h"
#include "../shared.h"
+#include "../db/mongo_access.h"
+
+mongo_access mongo;
using bsoncxx::builder::stream::close_array;
@@ -40,6 +43,8 @@ UmosapiService::UmosapiService(Address addr)
{ }
void UmosapiService::init(size_t thr = 2) {
+ auto uri = mongocxx::uri{config["mongoURI"]};
+ mongo.configure(std::move(uri));
auto opts = Http::Endpoint::options()
.threads(thr);
httpEndpoint->init(opts);
@@ -101,9 +106,9 @@ void UmosapiService::createDescription() {
}
void UmosapiService::retrieveAll(const Rest::Request& request, Http::ResponseWriter response) {
- mongocxx::client conn{mongocxx::uri{config["mongoURI"]}};
+ auto conn = mongo.get_connection();
- auto collection = conn[config["mongo_db"]][request.param(":mcollection").as<string>()];
+ auto collection = (*conn)[config["mongo_db"]][request.param(":mcollection").as<string>()];
auto cursor = collection.find({});