Parameters
options «Object|String» Either the paths to populate or an object specifying all parameters
[options.retainNullValues=false] «boolean» By default, Mongoose removes null and undefined values from populated arrays. Use this option to make retain
null
andundefined
array entries.[options.clone=false] «boolean» When you do , blog posts with the same author will share 1 copy of an
author
doc. Enable this option to make Mongoose clone populated docs before assigning them.[options.match=null] «Object|Function» Add an additional filter to the populate query. Can be a filter object containing MongoDB query syntax, or a function that returns a filter object.
[options.skipInvalidIds=false] «Boolean» By default, Mongoose throws a cast error if
localField
andforeignField
schemas don’t line up. If you enable this option, Mongoose will instead filter out anylocalField
properties that cannot be casted toforeignField
‘s schema type.[callback(err,doc)] «Function» Optional callback, executed upon completion. Receives
err
and the .
Returns:
- «Promise»
Populates document references.
Available top-level options:
- path: space delimited path(s) to populate
- select: optional fields to select
- match: optional query conditions to match
- model: optional name of the model to use for population
- justOne: optional boolean, if true Mongoose will always set
path
to an array. Inferred from schema by default.