aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/uobject.cpp16
-rw-r--r--db/uobject.h23
2 files changed, 39 insertions, 0 deletions
diff --git a/db/uobject.cpp b/db/uobject.cpp
new file mode 100644
index 0000000..769631e
--- /dev/null
+++ b/db/uobject.cpp
@@ -0,0 +1,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);
+}
diff --git a/db/uobject.h b/db/uobject.h
new file mode 100644
index 0000000..b4c2ef0
--- /dev/null
+++ b/db/uobject.h
@@ -0,0 +1,23 @@
+#ifndef Uobject_H_
+#define Uobject_H_
+
+#include <bsoncxx/builder/stream/document.hpp>
+#include <bsoncxx/json.hpp>
+
+#include <mongocxx/client.hpp>
+#include <mongocxx/instance.hpp>
+
+#include <mongocxx/client.hpp>
+#include <mongocxx/stdx.hpp>
+#include <mongocxx/uri.hpp>
+
+#include <json-c/json.h>
+
+#include "../shared.h"
+#include "../db/mongo_access.h"
+
+namespace uobject {
+ std::string retrieveAll(std::string collection, struct json_object* jsonObjects);
+}
+
+#endif