Schema.prototype.post()
Parameters
The «String|RegExp» method name or regular expression to match method name
[options] «Object»
[options.document] «Boolean» If
name
is a hook for both document and query middleware, set totrue
to run on document middleware.[options.query] «Boolean» If
name
is a hook for both document and query middleware, set totrue
to run on query middleware.fn «Function» callback
Defines a post hook for the document
const schema = new Schema(..);
schema.post('save', function (doc) {
console.log('this fired after a document was saved');
});
schema.post('find', function(docs) {
console.log('this fired after you ran a find query');
});
schema.post(/Many$/, function(res) {
console.log('this fired after you ran `updateMany()` or `deleteMany()`);
});
const Model = mongoose.model('Model', schema);
const m = new Model(..);
m.save(function(err) {
console.log('this fires after the `post` hook');
});
m.find(function(err, docs) {
console.log('this fires after the post find hook');
});
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .