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';
8
8
import { getExcludedFields } from './utils' ;
9
9
10
10
export default function plugin ( schema : MongooseSchema < any > , options ?: OptionsT ) {
11
+ // $FlowFixMe
11
12
if ( ! schema . options . versionKey )
12
13
throw new Error ( `You must provide 'versionKey' option to your schema or remain it as default` ) ;
13
14
@@ -26,8 +27,8 @@ export default function plugin(schema: MongooseSchema<any>, options?: OptionsT)
26
27
} ) ;
27
28
28
29
schema . pre ( 'save' , async function ( ) {
29
- // && this._original
30
- if ( ! this . isNew ) {
30
+ if ( ! this . isNew && this . _original ) {
31
+ await this . increment ( ) ;
31
32
const lhs = this . _original ;
32
33
const rhs = this . toObject ( ) ;
33
34
const version = this [ versionKey ] + 1 ; // cause we're inside preSave hook
You can’t perform that action at this time.
0 commit comments