mongodb.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <memory>
5#include <string>
6
7#include <SimoxUtility/json.h>
8
10
11#include <bsoncxx/builder/stream/array.hpp>
12#include <bsoncxx/builder/stream/document.hpp>
13#include <bsoncxx/builder/stream/helpers.hpp>
14#include <bsoncxx/json.hpp>
15#include <mongocxx/client.hpp>
16#include <mongocxx/instance.hpp>
17#include <mongocxx/pool.hpp>
18#include <mongocxx/stdx.hpp>
19#include <mongocxx/uri.hpp>
20
22{
23
24 namespace detail
25 {
26 inline const std::map<std::string, std::string> EscapeTable = {{"/", "|"}};
27
28 std::string escapeName(const std::string& segmentName);
29
30 std::string unescapeName(const std::string& escapedName);
31
32 bool insert(mongocxx::collection& coll, const nlohmann::json& value);
33
34 std::optional<nlohmann::json> contains(mongocxx::collection& coll,
35 const nlohmann::json& value);
36
37 bool update(mongocxx::collection& coll,
38 const nlohmann::json& query,
39 const std::string& vkey,
40 const nlohmann::json& vdata);
41 } // namespace detail
42
43 std::string toDocumentID(const armem::MemoryID&);
44 std::string toCollectionName(const armem::MemoryID&);
45
46 std::optional<mongocxx::database> databaseExists(mongocxx::client&,
47 const std::string& databaseName);
48 mongocxx::database ensureDatabaseExists(mongocxx::client&,
49 const std::string& databaseName,
50 bool createIfNotExistent);
51
52 std::optional<mongocxx::collection> collectionExists(mongocxx::database&,
53 const std::string& collectionName);
54 mongocxx::collection ensureCollectionExists(mongocxx::database&,
55 const std::string& collectionName,
56 bool createIfNotExistent);
57
58 std::optional<nlohmann::json> documentExists(mongocxx::collection& collection,
59 const nlohmann::json& query);
60
61 nlohmann::json ensureDocumentExists(mongocxx::collection& collection,
62 const nlohmann::json& query,
63 bool createIfNotExistent = false);
64
65 nlohmann::json readDataFromDocument(mongocxx::collection& collection,
66 const nlohmann::json& query);
67
68 void writeDataToDocument(mongocxx::collection& collection,
69 const nlohmann::json& query,
70 const nlohmann::json& data);
71
72 std::vector<nlohmann::json> getAllDocuments(mongocxx::collection& collection);
73
74} // namespace armarx::armem::server::ltm::util::mongodb
std::string unescapeName(const std::string &escapedName)
Definition mongodb.cpp:31
std::string escapeName(const std::string &segmentName)
Definition mongodb.cpp:19
std::optional< nlohmann::json > contains(mongocxx::collection &coll, const nlohmann::json &value)
Definition mongodb.cpp:54
bool insert(mongocxx::collection &coll, const nlohmann::json &value)
Definition mongodb.cpp:44
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition mongodb.cpp:68
const std::map< std::string, std::string > EscapeTable
Definition mongodb.h:26
std::optional< mongocxx::database > databaseExists(mongocxx::client &client, const std::string &databaseName)
Definition mongodb.cpp:84
mongocxx::collection ensureCollectionExists(mongocxx::database &db, const std::string &collectionName, bool createIfNotExistent)
Definition mongodb.cpp:122
std::optional< nlohmann::json > documentExists(mongocxx::collection &collection, const nlohmann::json &json)
Definition mongodb.cpp:176
std::vector< nlohmann::json > getAllDocuments(mongocxx::collection &collection)
Definition mongodb.cpp:240
void writeDataToDocument(mongocxx::collection &collection, const nlohmann::json &query, const nlohmann::json &update)
Definition mongodb.cpp:222
nlohmann::json ensureDocumentExists(mongocxx::collection &collection, const nlohmann::json &json, bool createIfNotExistent)
Definition mongodb.cpp:182
mongocxx::database ensureDatabaseExists(mongocxx::client &client, const std::string &databaseName, bool createIfNotExistent)
Definition mongodb.cpp:95
std::optional< mongocxx::collection > collectionExists(mongocxx::database &db, const std::string &collectionName)
Definition mongodb.cpp:112
nlohmann::json readDataFromDocument(mongocxx::collection &collection, const nlohmann::json &json)
Definition mongodb.cpp:211
std::string toCollectionName(const armem::MemoryID &id)
Definition mongodb.cpp:151
std::string toDocumentID(const armem::MemoryID &id)
Definition mongodb.cpp:139