I have a collection of documents stored in my mongodb database, each structured like this:
{
"current" :
{
"aksd" : "5555",
"BullevardBoh" : "123"
},
"history" :
{ "1" : {
"deleted" : false,
"added" : false,
"date" : "21-08-2014"
}
},
{ "2" : {
"deleted" : false,
"added" : false,
"date" : "01-01-2013"
}
},
"_id" : ObjectId("53f74dad2cbfdc136a07bf16"),
"__v" : 0
}
My goal now is to accomplish two tasks with my Mongoose/Express API.
To query for all nested
"current"
objects in each document and retrieve them as JSON objects, such as:
.{"aksd":"5555","BullevardBoh":"123"},{..},{..}
To retrieve all history revisions (1,2...) where the
"date"
is before a specified date.
This setup represents a versioning system that I am implementing. I am also curious if MongoDB will index this data structure efficiently or if there might be a better alternative, perhaps using arrays within objects?
The following MongoDB query does not work:
db.ips.findOne({current.aksd: {$exists:true}});