Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple mongoose pre save middleware

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();
});
like image 789
Aryeh Armon Avatar asked Feb 06 '17 15:02

Aryeh Armon


1 Answers

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] ] ],
like image 75
Aryeh Armon Avatar answered Oct 10 '22 01:10

Aryeh Armon