Skip to content

Commit

Permalink
fix(document): copy atomics when setting document array to an existin…
Browse files Browse the repository at this point in the history
…g document array

Fix #7472
  • Loading branch information
vkarpov15 committed Feb 5, 2019
1 parent a4e33dd commit e5948b8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/types/documentarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ function MongooseDocumentArray(values, path, doc) {
// TODO: replace this with `new CoreMongooseArray().concat()` when we remove
// support for node 4.x and 5.x, see https://i.imgur.com/UAAHk4S.png
const arr = new CoreMongooseArray();
if (Array.isArray(values)) {
values.forEach(v => {
arr.push(v);
});
}
arr._path = path;

const props = {
isMongooseDocumentArray: true,
Expand All @@ -59,6 +53,16 @@ function MongooseDocumentArray(values, path, doc) {
_handlers: void 0
};

if (Array.isArray(values)) {
if (values instanceof CoreMongooseArray) {
props._atomics = Object.assign({}, values._atomics);
}
values.forEach(v => {
arr.push(v);
});
}
arr._path = path;

// Values always have to be passed to the constructor to initialize, since
// otherwise MongooseArray#push will mark the array as modified to the parent.
const keysMA = Object.keys(MongooseArray.mixin);
Expand Down

0 comments on commit e5948b8

Please sign in to comment.