Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
it seems not, BUT you can specify in the scheme that a function be executed before saving the document, it is called pre-save hooks hooks or something like that, the
documentation is rather muddy, but there is
https://mongoosejs.com/docs/middleware.html#pre
const schema = new mongoose.Schema({ name: String });
// Mongoose will call this middleware function, because this script adds
// the middleware to the schema before compiling the model.
schema.pre('save', () => console.log('Hello from pre save')); // вот это
// Compile a model from the schema
const User = mongoose.model('User', schema);
new User({ name: 'test' }).save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question