diff --git a/lib/types/documentarray.js b/lib/types/documentarray.js index 1899980715c..89ca8c6421e 100644 --- a/lib/types/documentarray.js +++ b/lib/types/documentarray.js @@ -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, @@ -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);