I have the following mango code:
db.users.aggregate([ { $match: { $and: [ { UserName: { $eq: 'administrator' } }, { 'Company.CompanyName': { $eq: 'test' } } ] } }, { $lookup: { from: "companies", localField: "CompanyID", foreignField: "CompanyID", as: "Company" } }, ])
Part of the $lookup code works fine. I got the following result:

But if I add the $match code to the code, it will bring nothing.
I found that the problem is the second match: { 'Company.CompanyName': { $eq: 'test' } } , but I canβt understand what is wrong with it. Any ideas?
UPDATE:
I also tried $unwind on the result of $lookup , but no luck:
db.users.aggregate([ { $match: { $and: [ { UserName: { $eq: 'administrator' } }, { 'Company.CompanyName': { $eq: 'edt5' } } ] } }, { unwind: '$Company' }, { $lookup: { from: 'companies', localField: 'CompanyID', foreignField: 'CompanyID', as: 'Company' } }, ])
source share