Skip to content

Commit

Permalink
fix(schema): retain _id: false in schema after nesting in another s…
Browse files Browse the repository at this point in the history
…chema

Fix #8274
  • Loading branch information
vkarpov15 committed Oct 31, 2019
1 parent 78d5c4b commit 7dd63fd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/schema.js
Expand Up @@ -402,7 +402,6 @@ Schema.prototype.add = function add(obj, prefix) {
// the `_id` option. This behavior never worked before 5.4.11 but numerous
// codebases use it (see gh-7516, gh-7512).
if (obj._id === false && prefix == null) {
delete obj._id;
this.options._id = false;
}

Expand All @@ -417,6 +416,10 @@ Schema.prototype.add = function add(obj, prefix) {
throw new TypeError('Invalid value for schema path `' + fullPath +
'`, got value "' + obj[key] + '"');
}
// Retain `_id: false` but don't set it as a path, re: gh-8274.
if (key === '_id' && obj[key] === false) {
continue;
}

if (Array.isArray(obj[key]) && obj[key].length === 1 && obj[key][0] == null) {
throw new TypeError('Invalid value for schema Array path `' + fullPath +
Expand Down

0 comments on commit 7dd63fd

Please sign in to comment.