From 77c543d7c67febb91b30366ffe2ccb26deb5211b Mon Sep 17 00:00:00 2001 From: Adam Reis Date: Tue, 7 Nov 2017 20:31:58 +1300 Subject: [PATCH 1/2] Accept multiple paths or array of paths to depopulate - `Document.depopulate()` now accepts an array of paths, e.g. `['some', 'path', 'other.path']` - `Document.depopulate()` now accepts space separated paths, e.g. `'some path other.path'` - Fixes #5797 --- lib/document.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/document.js b/lib/document.js index 0a489eb5494..4d0ba9190c5 100644 --- a/lib/document.js +++ b/lib/document.js @@ -2592,12 +2592,17 @@ Document.prototype.populated = function(path, val, options) { */ Document.prototype.depopulate = function(path) { - var populatedIds = this.populated(path); - if (!populatedIds) { - return; + if (typeof path === 'string') { + path = path.split(' '); + } + for (const p of path) { + var populatedIds = this.populated(p); + if (!populatedIds) { + continue; + } + delete this.$__.populated[p]; + this.$set(p, populatedIds); } - delete this.$__.populated[path]; - this.$set(path, populatedIds); return this; }; From 3b07c00a444b51b1700615cdf64e71b8de0a1c6f Mon Sep 17 00:00:00 2001 From: Adam Reis Date: Tue, 7 Nov 2017 20:35:57 +1300 Subject: [PATCH 2/2] Use old school ES5 just in case --- lib/document.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/document.js b/lib/document.js index 4d0ba9190c5..b994048d380 100644 --- a/lib/document.js +++ b/lib/document.js @@ -2595,13 +2595,13 @@ Document.prototype.depopulate = function(path) { if (typeof path === 'string') { path = path.split(' '); } - for (const p of path) { - var populatedIds = this.populated(p); + for (var i = 0; i < path.length; i++) { + var populatedIds = this.populated(path[i]); if (!populatedIds) { continue; } - delete this.$__.populated[p]; - this.$set(p, populatedIds); + delete this.$__.populated[path[i]]; + this.$set(path[i], populatedIds); } return this; };