populate
noun
say it: “POP-yuh-layt” /ˈpɑpjəˌleɪt/
A Mongoose method that replaces a stored id with the document it points to, by running a second query.
What does populate do in Mongoose?
populate is a Mongoose query method that swaps a stored reference, such as a pet's _id in an adoption application, for the whole document it points to. Mongoose does it by sending a second query, so it isn't a join inside the database.
const application = await Application.findById(applicationId).populate("pet");
console.log(application.pet.name); // 'Biscuit'
In a sentence
- “Each populate is one more query, so the list page populates only what it shows.”
- “Calling populate on pet filled each adoption application with the pet's name and photo.”
Level: Journeyman · More MongoDB terms at this level
Updated