Reputation: 2185
I'd like to use multiple pre-save mongoose Middleware for a single schema, is this possible?
Example:
var schema = new Schema(..);
schema.pre('save', function(next) {
// do stuff
next();
});
schema.pre('save', function(next) {
// do another thing
next();
});
Upvotes: 12
Views: 4791
Reputation: 2185
INDEED i can. I inspected the schema object and found the following property:
callQueue:
[ [ 'pre', [Object] ],
[ 'pre', [Object] ],
[ 'pre', [Object] ],
[ 'pre', [Object] ],
[ 'pre', [Object] ],
[ 'pre', [Object] ],
[ 'pre', [Object] ] ],
Upvotes: 26