Need to understand the lookup vs 2 query performance

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.

Which method is more efficient?

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.

As Steeve says, performance is greatly affected by the number of read commands that the database has to perform.

If you often need to see which classes a user has, it could be a good idea to embed this information in the user’s document.