how to filter collection docs based on another collection?
Solution 1:
You can try a aggregation query with $lookup
stage to join user information, and $match
stage to match if user response if empty [],
const noUserFuncController = async (res, res) => {
const noUsersarr = await CaseFile.aggregate([
{
$lookup: {
from: "users", // confirm your collection name here
localField: "user",
foreignField: "userName",
as: "user"
}
},
{ $match: { user: [] } }
]);
res.json(noUsersarr);
}