Skip to content

Commit

Permalink
docs(schema): add Schema#virtuals to docs as a public property
Browse files Browse the repository at this point in the history
Fix #10829
  • Loading branch information
vkarpov15 committed Oct 4, 2021
1 parent d64f770 commit 4fb3fb0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,32 @@ Object.defineProperty(Schema.prototype, 'childSchemas', {
writable: true
});

/**
* Object containing all virtuals defined on this schema.
* The objects' keys are the virtual paths and values are instances of `VirtualType`.
*
* This property is typically only useful for plugin authors and advanced users.
* You do not need to interact with this property at all to use mongoose.
*
* ####Example:
* const schema = new Schema({});
* schema.virtual('answer').get(() => 42);
*
* console.log(schema.virtuals); // { answer: VirtualType { path: 'answer', ... } }
* console.log(schema.virtuals['answer'].getters[0].call()); // 42
*
* @api public
* @property virtuals
* @memberOf Schema
* @instance
*/

Object.defineProperty(Schema.prototype, 'virtuals', {
configurable: false,
enumerable: true,
writable: true
});

/**
* The original object passed to the schema constructor
*
Expand Down

0 comments on commit 4fb3fb0

Please sign in to comment.