$lookup aggregation handling

I am working in a project where I need to use mongodb aggregation pipeline. There is a most use case of $lookup. Its return an array of related data. In my query I have to use more than 10 $lookup in a single query and I want to merge all arrary in a single array. Is this possible?

Yes it is. You need to use $map and $mergeObjects. But if you want to merge the arrays you could do that in the application server or even the client code rather than the database server.

Yes it is but it is not advisable when you

If your use-case requires 10 $lookup, I really think you should work on your data model. There is no exact number for the numbers of $lookup but 10 seems excessive to me.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.