I want to understand the complexity of the 2 methods.
Query: I have two collection user and class. (a user can have multiple class)
Objective: Need to extract all user data with their class
method1: An aggregate query on user collection with class lookup
method2: An aggregate query to find users, then extract all userIds using looping(map), then perform a find query in class collection to extract those user’s classes using $in operator.
That is something that you should test yourself with your own data because it may differs from the usual. The usual being that a single access to the database should be more efficient. So method-1, in most cases, would be better.