Skip to content

Commit

Permalink
fix(document): handle directly setting embedded document array elemen…
Browse files Browse the repository at this point in the history
…t with projection

Fix #9909
  • Loading branch information
vkarpov15 committed Feb 16, 2021
1 parent de8fbf3 commit b4bb52d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/types/core_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,21 +284,15 @@ class CoreMongooseArray extends Array {
* @memberOf MongooseArray
*/

_markModified(elem, embeddedPath) {
_markModified(elem) {
const parent = this[arrayParentSymbol];
let dirtyPath;

if (parent) {
dirtyPath = this[arrayPathSymbol];

if (arguments.length) {
if (embeddedPath != null) {
// an embedded doc bubbled up the change
dirtyPath = dirtyPath + '.' + this.indexOf(elem) + '.' + embeddedPath;
} else {
// directly set an index
dirtyPath = dirtyPath + '.' + elem;
}
dirtyPath = dirtyPath + '.' + elem;
}

if (dirtyPath != null && dirtyPath.endsWith('.$')) {
Expand Down
28 changes: 28 additions & 0 deletions lib/types/documentarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,34 @@ class CoreDocumentArray extends CoreMongooseArray {
}
};
}

_markModified(elem, embeddedPath) {
const parent = this[arrayParentSymbol];
let dirtyPath;

if (parent) {
dirtyPath = this[arrayPathSymbol];

if (arguments.length) {
if (embeddedPath != null) {
// an embedded doc bubbled up the change
const index = elem.__index;
dirtyPath = dirtyPath + '.' + index + '.' + embeddedPath;
} else {
// directly set an index
dirtyPath = dirtyPath + '.' + elem;
}
}

if (dirtyPath != null && dirtyPath.endsWith('.$')) {
return this;
}

parent.markModified(dirtyPath, arguments.length > 0 ? elem : parent);
}

return this;
}
}

if (util.inspect.custom) {
Expand Down

0 comments on commit b4bb52d

Please sign in to comment.