aboutsummaryrefslogtreecommitdiff
path: root/db/uobject.cpp
blob: 769631e3b1666253cb6a7df57ac67a8cb7b46ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "uobject.h"

std::string uobject::retrieveAll(std::string collection, struct json_object* jsonObjects) {

    auto conn = mongo.get_connection();

    auto coll = (*conn)[config["mongo_db"]][collection];

    auto cursor = coll.find({});

    for (auto&& doc : cursor) {
        json_object_array_add(jsonObjects, json_tokener_parse(bsoncxx::to_json(doc).c_str()));
    }

    return json_object_to_json_string_ext(jsonObjects, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
}