I have one collection called Resources with documents inside:
{
"_id" : "fGR4ECcw5p2HFgxd3",
"ownerId" : "J8MpsWChPQdET6jwQ",
"inventory" : [
{
"_id" : ObjectId("5b537ef5895adfeae037e0a4"),
"quantity" : 17
},
{
"_id" : ObjectId("5b537d9c895adfeae037dbd2"),
"quantity" : 6
},
{
"_id" : ObjectId("5b5868e081702f675304290e"),
"quantity" : 26
},
{
"_id" : ObjectId("5b5eba8276dd90bd75e27f13"),
"quantity" : 85
},
{
"_id" : ObjectId("5b5ee58176dd90bd75e2f35f"),
"quantity" : 5
},
{
"_id" : ObjectId("5b62275686f92e050a9d50b2"),
"quantity" : 3
}
]
}
What i am trying to do is get object of inventory array with that objects id
Resources.find({
"ownerId": userid
},
{
fields:{
"inventory": {
"$elemMatch": {
"_id": ObjectId
}
}
}
})
I feel like this should work but its not It returns:
[ { _id: 'fGR4ECcw5p2HFgxd3' } ]
i tried with raw query and promise.await result is same.
I am expecting this as result:
{
"_id": "fGR4ECcw5p2HFgxd3",
"inventory": [
{
"_id": ObjectId("5b537ef5895adfeae037e0a4"),
"quantity": 17
}
]
}
Here it works:
https://mongoplayground.net/p/xtO32b5ahZS
But in meteor i do exactly same but i get above weird output.Is this a bug ?