does mongoose have an isDirty check?

mongoose, node.js

Solution

You may use the modified getter:

if (doc.modified) {
   // :)
}

Problem

I have a mongoose setup which involves an embedded-schema, lets say: A Blogpost with embedded comments. Comments can be edited by the original publisher as well as by an editor/admin. After adding / editing a comment the entire blogpost is saved. I have some custom mongoose's 'pre' middleware set up on the embedded comment-schema which automatically sets the lasteditdate for that particular comment. The thing is that 'pre' is called on EVERY comment on the blogpost, since I call save() on the blogpost. (For other reasons I need to do it like this) . Therefore, I need a way to check which comments have changed (or are new) since they were last saved (as part of the Blogpost overall save()) The questio: how to check in 'pre' whether a comment has changed or not? Obviously calling `this.isNew` isn't sufficient, since comments could be edited (i.e: aren't new) as well. Is there any `isDirty` or similar that I'm overlooking?

Original source