In Mongoose, you can use the Document isModified(@STRING) method.
The latest documentation for the method can be found here .
So, to check for a specific property with doc.isModified, you can do this:
doc.comments[4].message = "Hi, I've made an edit to my post"; // inside pre hook if ( this.isModified('comments') ) { // do something }
If you want to check for a specific comment, you can do this with the following entry this.isModified('comments.0.message')
Since the argument takes a string, if you needed to know exactly which comment was changed, you can scroll through each comment and run this.isModified('comments['+i+']message')
source share