File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import DiffModel from './DiffModel';
88import { getExcludedFields } from './utils' ;
99
1010export default function plugin ( schema : MongooseSchema < any > , options ?: OptionsT ) {
11+ // $FlowFixMe
1112 if ( ! schema . options . versionKey )
1213 throw new Error ( `You must provide 'versionKey' option to your schema or remain it as default` ) ;
1314
@@ -26,8 +27,8 @@ export default function plugin(schema: MongooseSchema<any>, options?: OptionsT)
2627 } ) ;
2728
2829 schema . pre ( 'save' , async function ( ) {
29- // && this._original
30- if ( ! this . isNew ) {
30+ if ( ! this . isNew && this . _original ) {
31+ await this . increment ( ) ;
3132 const lhs = this . _original ;
3233 const rhs = this . toObject ( ) ;
3334 const version = this [ versionKey ] + 1 ; // cause we're inside preSave hook
You can’t perform that action at this time.
0 commit comments