Does $lookup have any restrictions

Does $lookup has a restrictions on mognodb versions ?

is bit tricky question to me, but one of my developer complaints $lookup is working on productions, having issues running on the staging environment, we are using same setup like productions on staging.

Thanks’

Hi @Naresh_bavisetty and welcome in the MongoDB Community :muscle: !

There are two considerations to be aware of in the $lookup operator.

  1. You cannot include the $out or the $merge stage in the $lookup stage.

  2. In the $lookup stage, the from collection cannot be sharded.

You can find more information about these restrictions in the MongoDB Docs.

1 Like

Hi @JoeKarlsson, it really helps! Thank you!

Thanks’
Naresh

Hello @Naresh_bavisetty

may I add to Joe’s answer one word of warning?

$lookup is NOT meant as replacement for a join. Very often I see folks modeling their data with a tabular (aka relational) mindset. This will not be fun in the end and you will not take advantage of the pros of the flexible datamodel MongoDB provides.
So whenever you think that you want to use $lookup - check your datamodel, check if embedding will help to avoid $lookup. Often this comes with a the notion of denormalized data and data duplication. This is not bad, you gain simplicity, and read speed - you pay with some more updates. It will be always a trade of and you will need to think a lot more than in SQL about your data moldel.
$lookup can make sense e.g. when your model works best in case need to you use references.

Cheers,
Michael

1 Like