Can you do $lookup joins on a sharded cluster?

I know we can use aggregations on sharded clusters. But is it possible to use $lookup and $graphLookup joins on sharded clusters?

Yes, you can. Condition is $lookup stage require running on the database’s primary shard and only on unsharded collection.

https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/#syntax

https://docs.mongodb.com/manual/core/aggregation-pipeline-sharded-collections/

Let me know if you need more details.

Kanika

Thank you. To clarify,

  1. You can use $lookup on a sharded cluster (db must be on primary shard).

  2. You cannot use $lookup on a sharded COLLECTION.

Thats correct! :slight_smile:

Kanika

1 Like