MongoDB get documents from a collection not in other collection
Solution 1:
This is simply caused by your $project
stage, after you run:
{
$project: {
"CompanyList.Movies.Code" : 1
}
},
You're data will look like this:
{
CompanyList: [
{
Movies: { code: "123", ... other fields }
}
]
}
Now you're trying to match "CompanyList.CodeCompany": "23"
, but the field CodeCompany
simply does not exist anymore as you did not provide it in the project stage.
So just change you're projection stage to include fields you will use in later stages:
{
$project: {
"CompanyList.Movies.Code" : 1,
"CompanyList.CodeCompany": 1
}
},