{
"_id" : ObjectId("605a3a82c8bbb404f4e6b643"),
"address" : [
{
"_id" : ObjectId("605a3a82c8bbb404f4e6b644"),
"street" : "123 Leon Street",
"state" : "WE",
"zip" : 11312
},
{
"_id" : ObjectId("605a3b3bc8bbb404f4e6b645"),
"street" : "123 King Street",
"state" : "WE",
"zip" : 99998
}
],
"firstName" : "Tetet",
"__v" : 1
}
lets say i have the id for the second nested object.
"_id" : ObjectId("605a3b3bc8bbb404f4e6b645")
how to get only the document that is related to that id and not the whole document?
so far I have tried:
db.contacts.find({"_id" : ObjectId("605a3a82c8bbb404f4e6b643")}, {"address._id": ObjectId("605a3b3bc8bbb404f4e6b645")}).pretty()
and gotten:
{
"_id" : ObjectId("605a3a82c8bbb404f4e6b643"),
"address" : [
{
"_id" : ObjectId("605a3b3bc8bbb404f4e6b645")
},
{
"_id" : ObjectId("605a3b3bc8bbb404f4e6b645")
}
]
}
I would ideally want to have the nested documents, not just the id. Can anyone help me?
Thank you kindly