You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The section "Instance Methods" under the documentation Schemas - https://mongoosejs.com/docs/guide.html#definition, has some code as shown below. It shows the Schema constructor function takes two arguments - [definition] and [options]. The options argument is a document with the key "methods".
While going through the API documentation, the Schema constructor has been detailed over there, and very specifically about its second argument - [options]. However, this key "methods" has not been found listed in the list of keys over there. The list of keys presently listed there also has been shown below. It does not include the key "methods".
How do you see it ? Is it a possible missing in the documentation ? If so, how can I help to take it forward and add it.
Thanks
WeDotheBest4you
// define a schema
const animalSchema = new Schema({ name: String, type: String },
{
// Assign a function to the "methods" object of our animalSchema through schema options.
// By following this approach, there is no need to create a separate TS type to define the type of the instance functions.
methods: {
findSimilarTypes(cb) {
return mongoose.model('Animal').find({ type: this.type }, cb);
}
}
});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi All,
The section "Instance Methods" under the documentation Schemas - https://mongoosejs.com/docs/guide.html#definition, has some code as shown below. It shows the Schema constructor function takes two arguments - [definition] and [options]. The options argument is a document with the key "methods".
While going through the API documentation, the Schema constructor has been detailed over there, and very specifically about its second argument - [options]. However, this key "methods" has not been found listed in the list of keys over there. The list of keys presently listed there also has been shown below. It does not include the key "methods".
How do you see it ? Is it a possible missing in the documentation ? If so, how can I help to take it forward and add it.
Thanks
WeDotheBest4you
// define a schema
const animalSchema = new Schema({ name: String, type: String },
{
// Assign a function to the "methods" object of our animalSchema through schema options.
// By following this approach, there is no need to create a separate TS type to define the type of the instance functions.
methods: {
findSimilarTypes(cb) {
return mongoose.model('Animal').find({ type: this.type }, cb);
}
}
});
=======
Options:
Options for Nested Schemas:
** end of list **
Beta Was this translation helpful? Give feedback.
All reactions