Have kind of a MongoDB issue here as Im trying to find a collection om matching IDs. As Im building kind of a tree structure based on MongoDB. I have objects that contains multiple attributes like name, parents and children for them to know there relations. Right now I can from and object go though its child ID and load each object one by one. I how ever noticed its much faster got get them as a collection.
So my question is now, how do I find ID of intrest in the collection on tree node objects represented in MongoDB.
example of how the mongoDB document can look
{
"_id" : ObjectId("523de6c6d7b47f1f74c98ba2"),
"IDType" : "root",
"Name" : "test root",
"Relations" : [{
"Children" : {
"ChildrenList" : ["523de725d7b47f1d0c8242f1", "523de746d7b47f1d0c8242f5"]
},
"Parents" : {
"ParentList" : []
}
}]
}
So, how would I find one of the IDs by matching by a ID in the ChildrenList ?
this as Relations is a array of Children and Parents. and these two contains array of IDs to be matched.
have tried this with out sucess.
IMongoQuery searchQuery = Query.ElemMatch("Children", Query.EQ("ChildrenList", "523de746d7b47f1d0c8242f5"));
"Children"field is a descendant of"Relations"so minimally you'll need to include that in your query."Relations.Children"