diff --git a/History.md b/History.md index 4d613b91f0a..f838a47b330 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,9 @@ +5.9.29 / 2020-08-13 +=================== + * fix(document): support setting nested path to itself when it has nested subpaths #9313 + * fix(model): make `syncIndexes()` report error if it can't create an index #9303 + * fix: handle auth error when Atlas username is incorrect #9300 + 5.9.28 / 2020-08-07 =================== * fix(connection): consistently stop buffering when "reconnected" is emitted #9295 diff --git a/lib/helpers/document/compile.js b/lib/helpers/document/compile.js index ae91183ea34..0868f24516c 100644 --- a/lib/helpers/document/compile.js +++ b/lib/helpers/document/compile.js @@ -141,7 +141,7 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) { if (v != null && v.$__isNested) { // Convert top-level to POJO, but leave subdocs hydrated so `$set` // can handle them. See gh-9293. - v = v.$__parent.get(v.$__.nestedPath); + v = v.$__parent.get(path); } const doc = this.$__[scopeSymbol] || this; doc.$set(path, v); diff --git a/lib/types/core_array.js b/lib/types/core_array.js index 29f03859d81..423933f42b7 100644 --- a/lib/types/core_array.js +++ b/lib/types/core_array.js @@ -703,7 +703,7 @@ class CoreMongooseArray extends Array { } /** - * Alias of [pull](#types_array_MongooseArray-pull) + * Alias of [pull](#mongoosearray_MongooseArray-pull) * * @see MongooseArray#pull #types_array_MongooseArray-pull * @see mongodb http://www.mongodb.org/display/DOCS/Updating/#Updating-%24pull @@ -955,4 +955,4 @@ function _checkManualPopulation(arr, docs) { } } -module.exports = CoreMongooseArray; \ No newline at end of file +module.exports = CoreMongooseArray; diff --git a/package.json b/package.json index a711ca83058..28eba65c88c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mongoose", "description": "Mongoose MongoDB ODM", - "version": "5.9.28", + "version": "5.9.29", "author": "Guillermo Rauch ", "keywords": [ "mongodb", diff --git a/test/document.test.js b/test/document.test.js index dc87c15b30d..b05fe9f98c1 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -9222,6 +9222,39 @@ describe('document', function() { }); }); + it('doesnt wipe out nested paths when setting a nested path to itself (gh-9313)', function() { + const schema = new Schema({ + nested: { + prop1: { type: Number, default: 50 }, + prop2: { + type: String, + enum: ['val1', 'val2'], + default: 'val1', + required: true + }, + prop3: { + prop4: { type: Number, default: 0 } + } + } + }); + + const Model = db.model('Test', schema); + + return co(function*() { + let doc = yield Model.create({}); + + doc = yield Model.findById(doc); + + doc.nested = doc.nested; + + assert.equal(doc.nested.prop2, 'val1'); + yield doc.save(); + + const fromDb = yield Model.collection.findOne({ _id: doc._id }); + assert.equal(fromDb.nested.prop2, 'val1'); + }); + }); + it('allows saving after setting document array to itself (gh-9266)', function() { const Model = db.model('Test', Schema({ keys: [{ _id: false, name: String }] }));