From 7c4b9951a94630dd0c68e1a9b9620836fb8cbbbc Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 23 Feb 2019 20:36:59 -0500 Subject: [PATCH] fix(schema): handle nested objects with `_id: false` Fix #7524 --- lib/schema.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/schema.js b/lib/schema.js index 361a01e0f46..fd7e197efae 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -396,7 +396,10 @@ Schema.prototype.add = function add(obj, prefix) { return; } - if (obj._id === false) { + // Special case: setting top-level `_id` to false should convert to disabling + // 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; }