How does mongoose populate work under the hood

Basically the model 'a' is containing an attribute 'd' which is referencing(pointing) towards the model 'j'.

So whenever we use

a.find({ b: 'thing' }).populate('d').exec(etc..)

Then through populate we can individually call properties of 'j' like :

  • d.k
  • d.l
  • d.m

Populate() helps us to call properties of other models.


Mongoose uses two queries to fulfill the request.

The a collection is queried to get the docs that match the main query, and then the j collection is queried to populate the d field in the docs.

You can see the queries Mongoose is using by enabling debug output:

mongoose.set('debug', true);