Skip to content

Commit 9d4c9d4

Browse files
committed
Merge branch 'master' into 4.10
Conflicts: lib/schema.js package.json test/document.test.js
2 parents 636e922 + 8ba7869 commit 9d4c9d4

File tree

9 files changed

+51
-18
lines changed

9 files changed

+51
-18
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
**What is the current behavior?**
66

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

1010
**What is the expected behavior?**
1111

History.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
4.9.10 / 2017-05-17
2+
===================
3+
* fix(connection): ensure callback arg to openSet() is handled properly #5249
4+
* docs: remove dead plugins repo and add content links #5247
5+
* fix(model): skip index build if connecting after model init and autoIndex false #5176
6+
17
4.9.9 / 2017-05-13
28
==================
39
* docs: correct value for Query#regex() #5230

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed
2222

2323
## Plugins
2424

25-
Check out the [plugins search site](http://plugins.mongoosejs.io/) to see hundreds of related modules from the community.
26-
27-
Build your own Mongoose plugin through [generator-mongoose-plugin](https://github.com/huei90/generator-mongoose-plugin).
25+
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).
2826

2927
## Contributors
3028

docs/populate.jade

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ block content
330330
BandSchema.virtual('members', {
331331
ref: 'Person', // The model to use
332332
localField: 'name', // Find people where `localField`
333-
foreignField: 'band' // is equal to `foreignField`
333+
foreignField: 'band', // is equal to `foreignField`
334+
// If `justOne` is false, 'members' will be a single doc as opposed to
335+
// an array. `justOne` is false by default.
336+
justOne: false
334337
});
335338

336339
var Person = mongoose.model('Person', personSchema);

lib/connection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ Connection.prototype._handleOpenSetArgs = function(uris, database, options, call
487487
if (options && options.config) {
488488
this.config.autoIndex = options.config.autoIndex !== false;
489489
}
490+
491+
return callback;
490492
};
491493

492494
/*!

lib/document.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,18 +624,6 @@ Document.prototype.set = function(path, val, type, options) {
624624
var schema;
625625
var parts = path.split('.');
626626

627-
// gh-4578, if setting a deeply nested path that doesn't exist yet, create it
628-
var cur = this._doc;
629-
var curPath = '';
630-
for (i = 0; i < parts.length - 1; ++i) {
631-
cur = cur[parts[i]];
632-
curPath += (curPath.length > 0 ? '.' : '') + parts[i];
633-
if (!cur) {
634-
this.set(curPath, {});
635-
cur = this.getValue(curPath);
636-
}
637-
}
638-
639627
if (pathType === 'adhocOrUndefined' && strict) {
640628
// check for roots that are Mixed types
641629
var mixed;
@@ -670,6 +658,18 @@ Document.prototype.set = function(path, val, type, options) {
670658
schema = this.$__path(path);
671659
}
672660

661+
// gh-4578, if setting a deeply nested path that doesn't exist yet, create it
662+
var cur = this._doc;
663+
var curPath = '';
664+
for (i = 0; i < parts.length - 1; ++i) {
665+
cur = cur[parts[i]];
666+
curPath += (curPath.length > 0 ? '.' : '') + parts[i];
667+
if (!cur) {
668+
this.set(curPath, {});
669+
cur = this.getValue(curPath);
670+
}
671+
}
672+
673673
var pathToMark;
674674

675675
// When using the $set operator the path to the field must already exist.

lib/model.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ for (var i in EventEmitter.prototype) {
861861

862862
Model.init = function init() {
863863
if ((this.schema.options.autoIndex) ||
864-
(this.schema.options.autoIndex === null && this.db.config.autoIndex)) {
864+
(this.schema.options.autoIndex == null && this.db.config.autoIndex)) {
865865
this.ensureIndexes({ __noPromise: true, _automatic: true });
866866
}
867867

@@ -955,6 +955,11 @@ function _ensureIndexes(model, options, callback) {
955955
};
956956

957957
var create = function() {
958+
if (model.schema.options.autoIndex === false ||
959+
(model.schema.options.autoIndex == null && model.db.config.autoIndex === false)) {
960+
return done();
961+
}
962+
958963
var index = indexes.shift();
959964
if (!index) return done();
960965

lib/schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ Schema.prototype.clone = function() {
309309
s.methods = utils.clone(this.methods);
310310
s.statics = utils.clone(this.statics);
311311
s.plugins = Array.prototype.slice.call(this.plugins);
312+
s._indexes = utils.clone(this._indexes);
312313
s.s.hooks = this.s.hooks.clone();
313314
return s;
314315
};

test/document.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,6 +4064,24 @@ describe('document', function() {
40644064
done();
40654065
});
40664066

4067+
it('deeply nested virtual paths (gh-5250)', function(done) {
4068+
var TestSchema = new Schema({});
4069+
TestSchema.
4070+
virtual('a.b.c').
4071+
get(function() {
4072+
return this.v;
4073+
}).
4074+
set(function(value) {
4075+
this.v = value;
4076+
});
4077+
4078+
var TestModel = db.model('gh5250', TestSchema);
4079+
var t = new TestModel({'a.b.c': 5});
4080+
assert.equal(t.a.b.c, 5);
4081+
4082+
done();
4083+
});
4084+
40674085
it('JSON.stringify nested errors (gh-5208)', function(done) {
40684086
var AdditionalContactSchema = new Schema({
40694087
contactName: {

0 commit comments

Comments
 (0)