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:

  1. doc
  2. .populate('company')
  3. .populate({
  4. path: 'notes',
  5. match: /airline/,
  6. select: 'text',
  7. model: 'modelName'
  8. options: opts
  9. }, function (err, user) {
  10. assert(doc._id === user._id) // the document itself is passed
  11. })
  12. // summary
  13. doc.populate(path) // not executed
  14. doc.populate(options); // not executed
  15. doc.populate(path, callback) // executed
  16. doc.populate(options, callback); // executed
  17. doc.populate(callback); // executed
  18. 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.