I use mongo, and I have a little problem here. I want to get a record, but I just have the id of an array list inside record. This is what my data looks like.
{
"_id": ObjectId("1113000001"),
"menu": "desertsunday",
"fruit": {
"0": ObjectId("102b000000"),
"1": ObjectId("5200000000"),
"2": ObjectId("2900000000"),
"3": ObjectId("9870000002") }
}
I just have 102b000000 for get the record, I need to get the menu from there but I can’t get it with standard mongo. Can anybody help me ?
Actually fruit in you schema is not array, it is list of objects, because of this there is only one way to get root document by one fruit id:
In above query you should know ordinal number of fruit to fetch root document.
But if you can redesign your database as follows:
you can easy fetch root doc by embedded array item id: