I have 2 collections: Resources and Repo. Resources has a RepoId property.
I want to find all documents in Resources that have a RepoId that doesn’t exist in the Repo collection.
I have used the following query in MongDB Compass CLI (3.4.10 Community):
db.resources.aggregate(
[
{
$lookup: {
from: "RepositoryInfo",
localField: "repoId",
foreignField: "_id",
as: "repo",
},
},
]
);
This returns a repo field that is either an empty array, or an array with 1 object (the Repo document).
How can I filter this aggregated data so only results with an empty array are returned?