Skip to content

Commit

Permalink
Merge branch 'master' into 5.10
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Aug 14, 2020
2 parents 3e10b06 + 4f833ff commit f2e635e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/document/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/types/core_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -955,4 +955,4 @@ function _checkManualPopulation(arr, docs) {
}
}

module.exports = CoreMongooseArray;
module.exports = CoreMongooseArray;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mongoose",
"description": "Mongoose MongoDB ODM",
"version": "5.9.28",
"version": "5.9.29",
"author": "Guillermo Rauch <[email protected]>",
"keywords": [
"mongodb",
Expand Down
33 changes: 33 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }] }));

Expand Down

0 comments on commit f2e635e

Please sign in to comment.