I cannot reconstruct this: Retrieve only the queried element in an object array in MongoDB collection.
Remember, there are two id which should match and I want the Image: [] back. This is my structur.
{
"_id" : ObjectId("5ee4e57a6e5a926bdeb1e406"),
"Display" : [
{
"_id" : ObjectId("5ee5b7db9245084840dc624f"),
"Image" : [
{Document I want},
{Document I want}]
}
]
}
My best try:
db.User.aggregate([
{"$match" :
{"_id": ObjectId("5ee4e57a6e5a926bdeb1e406")}
},{
"$project" :{
"Display" : {
$filter: {
input: ObjectId("5ee5b7db9245084840dc624f"),
as: "id",
cond: {
"$Display._id": "$$id"}
}
}
}
}]);