Search code examples
databasemongodbnosqlaggregatemongo-shell

MongoDB aggregate returning an empty array


So, my problem is, that in MongoDB that .aggregate() function is not working

Heres some pictures:

mongo shell friendRequests collection users collection

You can see what a tried on the first picture


Solution

  • When using "$lookup", it's important that both "localField" values and "foreignField" values have the same type.

    In this case, "localField" is a string and "foreignField" is an ObjectId.

    It's probably best for queries to use ObjectId's for both.