DEV Community

Discussion on: How to use Populate in Mongoose & Node.js

Collapse
 
laygir profile image
Liger

Mongo newbie here πŸ‘‹πŸ»
Is it possible to do findOne after the populate?

The query string I have available belongs to the referenced document. I would like to first populate it and then find the document I am looking for.

Other wise I first need to do a findOne in one collection and pass the result to another collection’s findOne.

I am trying to avoid an unnecessary findOne operation but maybe I am overthinking it and its okay to do multiple findOne’s to reach a result?

Another solution comes to my mind is to make the query string I have available an indexed unique field so I can directly do findOne.

Collapse
 
paras594 profile image
Paras πŸ§™β€β™‚οΈ

Great point you made there. I never tried that, but I guess you can give it try. For cases like these, I tend to use aggregation.