node.js - mongoose middleware pre update -


i using

schema.pre('save', function (next) {   if (this.ismodified('field')) {     //do   } }); 

but need use same function ismodified in schema.pre('update' hook, not exists. know how can use same functionality in update hook?

not possible according this:

query middleware differs document middleware in subtle important way: in document middleware, refers document being updated. in query middleware, mongoose doesn't have reference document being updated, refers query object rather document being updated.

update query middleware , this refers query object has no ismodified method.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -