How to use the models function from mongoose
Find comprehensive JavaScript mongoose.models code examples handpicked from public code repositorys.
84 85 86 87 88 89 90 91 92 93
## mongoose basics > * your models extends from mongoose.Model > * schemas are stored on global mongoose but models may not > * mongoose.models.ModelName equals to mongoose.model('ModelName') > * ModelName.schema equals to mongoose.modelSchemas.ModelName > * static methods should be extended on mongoose.Model with a dynamic context > * instance methods should be extended on mongoose.Model.prototype > * custom model static methods are stored in MyModel.schema.statics
7
48
6
+ 11 other calls in file
89 90 91 92 93 94 95 96 97
}); } }; // Export model delete mongoose.models.SurveyResponse delete mongoose.modelSchemas.SurveyResponse var SurveyResponse = mongoose.model('SurveyResponse', SurveyResponseSchema); module.exports = SurveyResponse;
29
38
24
84 85 86 87 88 89 90 91 92 93 94 95
// Small utility function for checking if email is already exists userSchema.path('email').validate(async function (value) { if (!this.isNew) return; const emailCount = await mongoose.models.User.countDocuments({ email: value, }); return !emailCount; }, 'Email already exists. Please Login with your existing Credentials.');
0
0
1
+ 7 other calls in file
mongoose.model is the most popular function in mongoose (2160 examples)