Schema.prototype.virtual()

Parameters
  • name «String»
  • [options] «Object»

  • [options.ref] «String|Model» model name or model instance. Marks this as a populate virtual.

  • [options.localField] «String|Function» Required for populate virtuals. See populate virtual docs for more information.

  • [options.foreignField] «String|Function» Required for populate virtuals. See populate virtual docs for more information.

  • [options.justOne=false] «Boolean|Function» Only works with populate virtuals. If truthy, will be a single doc or null. Otherwise, the populate virtual will be an array.

  • [options.count=false] «Boolean» Only works with populate virtuals. If truthy, this populate virtual will contain the number of documents rather than the documents themselves when you populate().

  • [options.get=null] «Function|null» Adds a getter to this virtual to transform the populated doc.

Returns:
  • «VirtualType»

Creates a virtual type with the given name.