Skip to content
Snippets Groups Projects
Commit 5e13f186 authored by Robin Müller's avatar Robin Müller
Browse files

Fixed create Collections

Now stores now created Data after start LTM Recording start
parent 5e1a578f
No related branches found
No related tags found
1 merge request!464Draft: Feature/mongo db
Pipeline #21034 failed
......@@ -245,7 +245,7 @@ namespace armarx::armem::server::ltm::detail::mixin
return util::mongodb::toCollectionName(_id);
}
std::vector<std::string>
/*std::vector<std::string>
MongoDBStorageMixin::getAllSubCollections() const
{
auto db = databaseExists();
......@@ -255,7 +255,7 @@ namespace armarx::armem::server::ltm::detail::mixin
// Normally not Reachable ?
}
return util::mongodb::getSubCollections(*db, _id);
}
}*/
std::string
MongoDBStorageMixin::getPreviousCollectionName() const
......
......@@ -54,7 +54,7 @@ namespace armarx::armem::server::ltm::detail::mixin
std::string getDocumentName() const;
std::string getCollectionName() const;
std::vector<std::string> getAllSubCollections() const;
//std::vector<std::string> getAllSubCollections() const;
std::string getPreviousCollectionName() const;
std::string getDatabaseName() const;
......
......@@ -12,12 +12,6 @@ namespace armarx::armem::server::ltm::util::mongodb
namespace bbuilder = bsoncxx::builder;
namespace bdoc = bsoncxx::document;
//Private Namespace for the CollectionNameDepth to use it like a Folder structure
namespace
{
size_t collectionNameDepth = 0;
}
namespace detail
{
std::string
......@@ -124,6 +118,7 @@ namespace armarx::armem::server::ltm::util::mongodb
//Workaround to create an empty Database client[databaseName] does not create a database if nothing is added
//db = client[databaseName];
//db.create_collection("empty");
ARMARX_INFO << "Create Database " << databaseName;
return client[databaseName];
}
return std::nullopt;
......@@ -154,7 +149,7 @@ namespace armarx::armem::server::ltm::util::mongodb
{
if (db.has_collection(collectionName))
{
return db.create_collection(collectionName);
return db[collectionName];
}
return std::nullopt;
}
......@@ -174,7 +169,7 @@ namespace armarx::armem::server::ltm::util::mongodb
}
}
//Workaround to create an empty Collection db[collectionName] does not create a Collection if no document is added
return db.create_collection(collectionName);
return db[collectionName];
}
std::string
......@@ -193,32 +188,28 @@ namespace armarx::armem::server::ltm::util::mongodb
toCollectionName(const armem::MemoryID& id)
{
ARMARX_CHECK(id.isWellDefined());
collectionNameDepth = 0;
std::stringstream ss;
if (id.hasMemoryName())
{
collectionNameDepth++;
ss << detail::escapeName(id.memoryName);
}
if (id.hasCoreSegmentName())
{
collectionNameDepth++;
ss << "." << detail::escapeName(id.coreSegmentName);
}
if (id.hasProviderSegmentName())
{
collectionNameDepth++;
ss << "." << detail::escapeName(id.providerSegmentName);
}
if (id.hasEntityName())
{
collectionNameDepth++;
ss << "." << detail::escapeName(id.entityName);
}
return ss.str();
}
/*unused
std::vector<std::string>
getDirectSuccessors(const std::vector<std::string>& collection_names, const std::string& prefix) {
std::vector<std::string> direct_successors;
......@@ -247,6 +238,7 @@ namespace armarx::armem::server::ltm::util::mongodb
getSubCollections(mongocxx::database& db, const armem::MemoryID& id) {
return getDirectSuccessors(detail::list_collection_names(db), toCollectionName(id));
}
*/
std::optional<nlohmann::json>
documentExists(mongocxx::collection& collection, const nlohmann::json& json)
......
......@@ -60,10 +60,10 @@ namespace armarx::armem::server::ltm::util::mongodb
const std::string& collectionName,
bool createIfNotExistent);
std::vector<std::string> getDirectSuccessors(const std::vector<std::string>& collection_names,
/*std::vector<std::string> getDirectSuccessors(const std::vector<std::string>& collection_names,
const std::string& prefix, int depth);
std::vector<std::string> getSubCollections(mongocxx::database& db, const armem::MemoryID& id);
std::vector<std::string> getSubCollections(mongocxx::database& db, const armem::MemoryID& id);*/
std::optional<nlohmann::json> documentExists(mongocxx::collection& collection,
const nlohmann::json& query);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment