Anshul Kai
Anshul Kai

Reputation: 4088

Is Mongoose Populate Smart?

I'm using mongoose populate to populate users for a related action. Most of my actions share the same user. Is mongoose smart enough to fetch the user only once or does it perform an unintelligent join?

Upvotes: 1

Views: 147

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311945

It will just fetch the referenced user once; in fact it will fetch all referenced users in a single query using _id: {$in: [...ids...]}.

You can confirm this by enabling debug output to the console via a call in your startup code so that you can see what queries Mongoose is performing:

mongoose.set('debug', true);

Upvotes: 2

Related Questions