Document.prototype.populate()
Parameters
[path] «String|Object» The path to populate or an options object
[callback] «Function» When passed, population is invoked
Returns:
- «Document» this
Populates document references, executing the callback
when complete. If you want to use promises instead, use this function with execPopulate()
Example:
doc
.populate('company')
.populate({
path: 'notes',
match: /airline/,
select: 'text',
model: 'modelName'
options: opts
}, function (err, user) {
assert(doc._id === user._id) // the document itself is passed
})
// summary
doc.populate(path) // not executed
doc.populate(options); // not executed
doc.populate(path, callback) // executed
doc.populate(options, callback); // executed
doc.populate(callback); // executed
doc.populate(options).execPopulate() // executed, returns promise
NOTE:
Population does not occur unless a callback
is passed or you explicitly call execPopulate()
. Passing the same path a second time will overwrite the previous path options. See Model.populate() for explaination of options.
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .