Skip to content

Commit ab8b347

Browse files
committed
fix(index): force increment version of doc
1 parent 3fad063 commit ab8b347

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import DiffModel from './DiffModel';
88
import { getExcludedFields } from './utils';
99

1010
export 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

0 commit comments

Comments
 (0)