Skip to content

Commit

Permalink
Merge branch 'master' into 4.10
Browse files Browse the repository at this point in the history
Conflicts:
	lib/schema.js
	package.json
	test/document.test.js
  • Loading branch information
vkarpov15 committed May 18, 2017
2 parents 636e922 + 8ba7869 commit 9d4c9d4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Expand Up @@ -5,7 +5,7 @@
**What is the current behavior?**

**If the current behavior is a bug, please provide the steps to reproduce.**
<!-- If you can, provide a stadalone script / gist to reproduce your issue -->
<!-- If you can, provide a standalone script / gist to reproduce your issue -->

**What is the expected behavior?**

Expand Down
6 changes: 6 additions & 0 deletions History.md
@@ -1,3 +1,9 @@
4.9.10 / 2017-05-17
===================
* fix(connection): ensure callback arg to openSet() is handled properly #5249
* docs: remove dead plugins repo and add content links #5247
* fix(model): skip index build if connecting after model init and autoIndex false #5176

4.9.9 / 2017-05-13
==================
* docs: correct value for Query#regex() #5230
Expand Down
4 changes: 1 addition & 3 deletions README.md
Expand Up @@ -22,9 +22,7 @@ Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed

## Plugins

Check out the [plugins search site](http://plugins.mongoosejs.io/) to see hundreds of related modules from the community.

Build your own Mongoose plugin through [generator-mongoose-plugin](https://github.com/huei90/generator-mongoose-plugin).
Check out the [plugins search site](http://plugins.mongoosejs.io/) to see hundreds of related modules from the community. Next, learn how to write your own plugin from the [docs](http://mongoosejs.com/docs/plugins.html) or [this blog post](http://thecodebarbarian.com/2015/03/06/guide-to-mongoose-plugins).

## Contributors

Expand Down
5 changes: 4 additions & 1 deletion docs/populate.jade
Expand Up @@ -330,7 +330,10 @@ block content
BandSchema.virtual('members', {
ref: 'Person', // The model to use
localField: 'name', // Find people where `localField`
foreignField: 'band' // is equal to `foreignField`
foreignField: 'band', // is equal to `foreignField`
// If `justOne` is false, 'members' will be a single doc as opposed to
// an array. `justOne` is false by default.
justOne: false
});

var Person = mongoose.model('Person', personSchema);
Expand Down
2 changes: 2 additions & 0 deletions lib/connection.js
Expand Up @@ -487,6 +487,8 @@ Connection.prototype._handleOpenSetArgs = function(uris, database, options, call
if (options && options.config) {
this.config.autoIndex = options.config.autoIndex !== false;
}

return callback;
};

/*!
Expand Down
24 changes: 12 additions & 12 deletions lib/document.js
Expand Up @@ -624,18 +624,6 @@ Document.prototype.set = function(path, val, type, options) {
var schema;
var parts = path.split('.');

// gh-4578, if setting a deeply nested path that doesn't exist yet, create it
var cur = this._doc;
var curPath = '';
for (i = 0; i < parts.length - 1; ++i) {
cur = cur[parts[i]];
curPath += (curPath.length > 0 ? '.' : '') + parts[i];
if (!cur) {
this.set(curPath, {});
cur = this.getValue(curPath);
}
}

if (pathType === 'adhocOrUndefined' && strict) {
// check for roots that are Mixed types
var mixed;
Expand Down Expand Up @@ -670,6 +658,18 @@ Document.prototype.set = function(path, val, type, options) {
schema = this.$__path(path);
}

// gh-4578, if setting a deeply nested path that doesn't exist yet, create it
var cur = this._doc;
var curPath = '';
for (i = 0; i < parts.length - 1; ++i) {
cur = cur[parts[i]];
curPath += (curPath.length > 0 ? '.' : '') + parts[i];
if (!cur) {
this.set(curPath, {});
cur = this.getValue(curPath);
}
}

var pathToMark;

// When using the $set operator the path to the field must already exist.
Expand Down
7 changes: 6 additions & 1 deletion lib/model.js
Expand Up @@ -861,7 +861,7 @@ for (var i in EventEmitter.prototype) {

Model.init = function init() {
if ((this.schema.options.autoIndex) ||
(this.schema.options.autoIndex === null && this.db.config.autoIndex)) {
(this.schema.options.autoIndex == null && this.db.config.autoIndex)) {
this.ensureIndexes({ __noPromise: true, _automatic: true });
}

Expand Down Expand Up @@ -955,6 +955,11 @@ function _ensureIndexes(model, options, callback) {
};

var create = function() {
if (model.schema.options.autoIndex === false ||
(model.schema.options.autoIndex == null && model.db.config.autoIndex === false)) {
return done();
}

var index = indexes.shift();
if (!index) return done();

Expand Down
1 change: 1 addition & 0 deletions lib/schema.js
Expand Up @@ -309,6 +309,7 @@ Schema.prototype.clone = function() {
s.methods = utils.clone(this.methods);
s.statics = utils.clone(this.statics);
s.plugins = Array.prototype.slice.call(this.plugins);
s._indexes = utils.clone(this._indexes);
s.s.hooks = this.s.hooks.clone();
return s;
};
Expand Down
18 changes: 18 additions & 0 deletions test/document.test.js
Expand Up @@ -4064,6 +4064,24 @@ describe('document', function() {
done();
});

it('deeply nested virtual paths (gh-5250)', function(done) {
var TestSchema = new Schema({});
TestSchema.
virtual('a.b.c').
get(function() {
return this.v;
}).
set(function(value) {
this.v = value;
});

var TestModel = db.model('gh5250', TestSchema);
var t = new TestModel({'a.b.c': 5});
assert.equal(t.a.b.c, 5);

done();
});

it('JSON.stringify nested errors (gh-5208)', function(done) {
var AdditionalContactSchema = new Schema({
contactName: {
Expand Down

0 comments on commit 9d4c9d4

Please sign in to comment.