I have two collections users{id, name} and files{id, userId, name} I want to find all the files whose file name "abc.xyz", I tried to write a code using $lookup but getting all the files belong to user and not filtering it by name "abc.xyz", I have written following query.
db.user.aggregate([
{"$lookup":
{
"from": "files",
"localField": "id",
"foreignField": "userId",
"as": "fileList"
}
},
{"$project": { "filList":{
"$filter": {
"input":"$fileList",
"as":"file"
"cond": {"$eq": ["$file.name","abc.xyz"]}
}
}
}
}
])
Thank you