Skip to content

Commit

Permalink
fix(schema): support setting _id option to false after instantiat…
Browse files Browse the repository at this point in the history
…ing schema

Fix #9390
  • Loading branch information
vkarpov15 committed Sep 7, 2020
1 parent 1b19af2 commit 31ad004
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/schema.js
Expand Up @@ -1656,6 +1656,16 @@ Schema.prototype.set = function(key, value, _tags) {
this.options[key] = value;
this._userProvidedOptions[key] = this.options[key];
break;
case '_id':
this.options[key] = value;
this._userProvidedOptions[key] = this.options[key];

if (value && !this.paths['_id']) {
addAutoId(this);
} else if (!value && this.paths['_id'] != null && this.paths['_id'].auto) {
this.remove('_id');
}
break;
default:
this.options[key] = value;
this._userProvidedOptions[key] = this.options[key];
Expand Down

0 comments on commit 31ad004

Please sign in to comment.