mongoose 4.12.2 → 4.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +11 -1
- package/lib/connection.js +7 -2
- package/lib/drivers/node-mongodb-native/connection.js +10 -0
- package/lib/error/browserMissingSchema.js +1 -1
- package/lib/error/cast.js +1 -1
- package/lib/error/disconnected.js +1 -1
- package/lib/error/divergentArray.js +1 -1
- package/lib/{error.js → error/index.js} +9 -9
- package/lib/error/missingSchema.js +1 -1
- package/lib/error/notFound.js +1 -1
- package/lib/error/objectExpected.js +1 -1
- package/lib/error/objectParameter.js +1 -1
- package/lib/error/overwriteModel.js +1 -1
- package/lib/error/strict.js +1 -1
- package/lib/error/validation.js +1 -1
- package/lib/error/validator.js +1 -1
- package/lib/error/version.js +1 -1
- package/lib/model.js +20 -7
- package/lib/query.js +2 -2
- package/lib/services/setDefaultsOnInsert.js +4 -4
- package/lib/services/updateValidators.js +5 -3
- package/lib/types/buffer.js +12 -3
- package/package.json +1 -1
package/History.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
4.12.
|
|
1
|
+
4.12.3 / 2017-10-16
|
|
2
|
+
===================
|
|
3
|
+
* fix(connection): emit 'reconnect' event as well as 'reconnected' for consistency with driver #5719
|
|
4
|
+
* fix: correctly bubble up left/joined events for replica set #5718
|
|
5
|
+
* fix(connection): allow passing in `autoIndex` as top-level option rather than requiring `config.autoIndex` #5711
|
|
6
|
+
* docs(connection): improve docs regarding reconnectTries, autoReconnect, and bufferMaxEntries #5711
|
|
7
|
+
* fix(query): handle null with addToSet/push/pull/pullAll update validators #5710
|
|
8
|
+
* fix(model): handle setDefaultsOnInsert option for bulkWrite updateOne and updateMany #5708
|
|
9
|
+
* fix(query): avoid infinite recursion edge case when cloning a buffer #5702
|
|
10
|
+
|
|
11
|
+
4.12.2 / 2017-10-14
|
|
2
12
|
===================
|
|
3
13
|
* docs(faq): add FAQ about using arrow functions for getters/setters, virtuals, and methods #5700
|
|
4
14
|
* docs(schema): document the childSchemas property and add to public API #5695
|
package/lib/connection.js
CHANGED
|
@@ -763,9 +763,13 @@ Connection.prototype.openUri = function(uri, options, callback) {
|
|
|
763
763
|
if (options) {
|
|
764
764
|
options = utils.clone(options, { retainKeyOrder: true });
|
|
765
765
|
delete options.useMongoClient;
|
|
766
|
-
|
|
767
|
-
|
|
766
|
+
var autoIndex = options.config && options.config.autoIndex != null ?
|
|
767
|
+
options.config.autoIndex :
|
|
768
|
+
options.autoIndex;
|
|
769
|
+
if (autoIndex != null) {
|
|
770
|
+
this.config.autoIndex = autoIndex !== false;
|
|
768
771
|
delete options.config;
|
|
772
|
+
delete options.autoIndex;
|
|
769
773
|
}
|
|
770
774
|
|
|
771
775
|
// Backwards compat
|
|
@@ -795,6 +799,7 @@ Connection.prototype.openUri = function(uri, options, callback) {
|
|
|
795
799
|
// Backwards compat for mongoose 4.x
|
|
796
800
|
db.on('reconnect', function() {
|
|
797
801
|
_this.readyState = STATES.connected;
|
|
802
|
+
_this.emit('reconnect');
|
|
798
803
|
_this.emit('reconnected');
|
|
799
804
|
});
|
|
800
805
|
db.s.topology.on('reconnectFailed', function() {
|
|
@@ -162,6 +162,7 @@ function listen(conn) {
|
|
|
162
162
|
});
|
|
163
163
|
conn.db.on('reconnect', function() {
|
|
164
164
|
conn.readyState = STATES.connected;
|
|
165
|
+
conn.emit('reconnect');
|
|
165
166
|
conn.emit('reconnected');
|
|
166
167
|
conn.onOpen();
|
|
167
168
|
});
|
|
@@ -171,6 +172,7 @@ function listen(conn) {
|
|
|
171
172
|
conn.db.on('open', function(err, db) {
|
|
172
173
|
if (STATES.disconnected === conn.readyState && db && db.databaseName) {
|
|
173
174
|
conn.readyState = STATES.connected;
|
|
175
|
+
conn.emit('reconnect');
|
|
174
176
|
conn.emit('reconnected');
|
|
175
177
|
}
|
|
176
178
|
});
|
|
@@ -204,6 +206,14 @@ NativeConnection.prototype.doOpenSet = function(fn) {
|
|
|
204
206
|
: new ReplSetServers(servers, this.options.replset || this.options.replSet);
|
|
205
207
|
this.db = new Db(this.name, server, this.options.db);
|
|
206
208
|
|
|
209
|
+
this.db.s.topology.on('left', function(data) {
|
|
210
|
+
_this.emit('left', data);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
this.db.s.topology.on('joined', function(data) {
|
|
214
|
+
_this.emit('joined', data);
|
|
215
|
+
});
|
|
216
|
+
|
|
207
217
|
this.db.on('fullsetup', function() {
|
|
208
218
|
_this.emit('fullsetup');
|
|
209
219
|
});
|
package/lib/error/cast.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = exports = MongooseError;
|
|
|
37
37
|
* @api public
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
MongooseError.messages = require('./
|
|
40
|
+
MongooseError.messages = require('./messages');
|
|
41
41
|
|
|
42
42
|
// backward compat
|
|
43
43
|
MongooseError.Messages = MongooseError.messages;
|
|
@@ -51,16 +51,16 @@ MongooseError.Messages = MongooseError.messages;
|
|
|
51
51
|
* @api public
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
|
-
MongooseError.DocumentNotFoundError = require('./
|
|
54
|
+
MongooseError.DocumentNotFoundError = require('./notFound');
|
|
55
55
|
|
|
56
56
|
/*!
|
|
57
57
|
* Expose subclasses
|
|
58
58
|
*/
|
|
59
59
|
|
|
60
|
-
MongooseError.CastError = require('./
|
|
61
|
-
MongooseError.ValidationError = require('./
|
|
62
|
-
MongooseError.ValidatorError = require('./
|
|
63
|
-
MongooseError.VersionError = require('./
|
|
64
|
-
MongooseError.OverwriteModelError = require('./
|
|
65
|
-
MongooseError.MissingSchemaError = require('./
|
|
66
|
-
MongooseError.DivergentArrayError = require('./
|
|
60
|
+
MongooseError.CastError = require('./cast');
|
|
61
|
+
MongooseError.ValidationError = require('./validation');
|
|
62
|
+
MongooseError.ValidatorError = require('./validator');
|
|
63
|
+
MongooseError.VersionError = require('./version');
|
|
64
|
+
MongooseError.OverwriteModelError = require('./overwriteModel');
|
|
65
|
+
MongooseError.MissingSchemaError = require('./missingSchema');
|
|
66
|
+
MongooseError.DivergentArrayError = require('./divergentArray');
|
package/lib/error/notFound.js
CHANGED
package/lib/error/strict.js
CHANGED
package/lib/error/validation.js
CHANGED
package/lib/error/validator.js
CHANGED
package/lib/error/version.js
CHANGED
package/lib/model.js
CHANGED
|
@@ -23,6 +23,7 @@ var isPathSelectedInclusive = require('./services/projection/isPathSelectedInclu
|
|
|
23
23
|
var mpath = require('mpath');
|
|
24
24
|
var parallel = require('async/parallel');
|
|
25
25
|
var parallelLimit = require('async/parallelLimit');
|
|
26
|
+
var setDefaultsOnInsert = require('./services/setDefaultsOnInsert');
|
|
26
27
|
var util = require('util');
|
|
27
28
|
var utils = require('./utils');
|
|
28
29
|
|
|
@@ -2239,12 +2240,18 @@ Model.bulkWrite = function(ops, options, callback) {
|
|
|
2239
2240
|
});
|
|
2240
2241
|
};
|
|
2241
2242
|
} else if (op['updateOne']) {
|
|
2243
|
+
op = op['updateOne'];
|
|
2242
2244
|
return function(callback) {
|
|
2243
2245
|
try {
|
|
2244
|
-
op['
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2246
|
+
op['filter'] = cast(_this.schema, op['filter']);
|
|
2247
|
+
op['update'] = castUpdate(_this.schema, op['update'],
|
|
2248
|
+
_this.schema.options.strict);
|
|
2249
|
+
if (op.setDefaultsOnInsert) {
|
|
2250
|
+
setDefaultsOnInsert(op['filter'], _this.schema, op['update'], {
|
|
2251
|
+
setDefaultsOnInsert: true,
|
|
2252
|
+
upsert: op.upsert
|
|
2253
|
+
});
|
|
2254
|
+
}
|
|
2248
2255
|
} catch (error) {
|
|
2249
2256
|
return callback(error);
|
|
2250
2257
|
}
|
|
@@ -2252,14 +2259,20 @@ Model.bulkWrite = function(ops, options, callback) {
|
|
|
2252
2259
|
callback(null);
|
|
2253
2260
|
};
|
|
2254
2261
|
} else if (op['updateMany']) {
|
|
2262
|
+
op = op['updateMany'];
|
|
2255
2263
|
return function(callback) {
|
|
2256
2264
|
try {
|
|
2257
|
-
op['
|
|
2258
|
-
|
|
2259
|
-
op['updateMany']['update'] = castUpdate(_this.schema, op['updateMany']['update'], {
|
|
2265
|
+
op['filter'] = cast(_this.schema, op['filter']);
|
|
2266
|
+
op['update'] = castUpdate(_this.schema, op['update'], {
|
|
2260
2267
|
strict: _this.schema.options.strict,
|
|
2261
2268
|
overwrite: false
|
|
2262
2269
|
});
|
|
2270
|
+
if (op.setDefaultsOnInsert) {
|
|
2271
|
+
setDefaultsOnInsert(op['filter'], _this.schema, op['update'], {
|
|
2272
|
+
setDefaultsOnInsert: true,
|
|
2273
|
+
upsert: op.upsert
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2263
2276
|
} catch (error) {
|
|
2264
2277
|
return callback(error);
|
|
2265
2278
|
}
|
package/lib/query.js
CHANGED
|
@@ -2227,7 +2227,7 @@ Query.prototype._findAndModify = function(type, callback) {
|
|
|
2227
2227
|
};
|
|
2228
2228
|
} else {
|
|
2229
2229
|
castedDoc = castDoc(this, opts.overwrite);
|
|
2230
|
-
castedDoc = setDefaultsOnInsert(this, schema, castedDoc, opts);
|
|
2230
|
+
castedDoc = setDefaultsOnInsert(this._conditions, schema, castedDoc, opts);
|
|
2231
2231
|
if (!castedDoc) {
|
|
2232
2232
|
if (opts.upsert) {
|
|
2233
2233
|
// still need to do the upsert to empty doc
|
|
@@ -2939,7 +2939,7 @@ function _update(query, op, conditions, doc, options, callback) {
|
|
|
2939
2939
|
}
|
|
2940
2940
|
}
|
|
2941
2941
|
|
|
2942
|
-
castedDoc = setDefaultsOnInsert(query, query.schema, castedDoc, options);
|
|
2942
|
+
castedDoc = setDefaultsOnInsert(query._conditions, query.schema, castedDoc, options);
|
|
2943
2943
|
if (!castedDoc) {
|
|
2944
2944
|
// Make sure promises know that this is still an update, see gh-2796
|
|
2945
2945
|
query.op = op;
|
|
@@ -5,7 +5,7 @@ var modifiedPaths = require('./common').modifiedPaths;
|
|
|
5
5
|
/**
|
|
6
6
|
* Applies defaults to update and findOneAndUpdate operations.
|
|
7
7
|
*
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {Object} filter
|
|
9
9
|
* @param {Schema} schema
|
|
10
10
|
* @param {Object} castedDoc
|
|
11
11
|
* @param {Object} options
|
|
@@ -13,7 +13,7 @@ var modifiedPaths = require('./common').modifiedPaths;
|
|
|
13
13
|
* @api private
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
module.exports = function(
|
|
16
|
+
module.exports = function(filter, schema, castedDoc, options) {
|
|
17
17
|
var keys = Object.keys(castedDoc || {});
|
|
18
18
|
var updatedKeys = {};
|
|
19
19
|
var updatedValues = {};
|
|
@@ -33,11 +33,11 @@ module.exports = function(query, schema, castedDoc, options) {
|
|
|
33
33
|
modifiedPaths(castedDoc, '', modified);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
var paths = Object.keys(
|
|
36
|
+
var paths = Object.keys(filter);
|
|
37
37
|
var numPaths = paths.length;
|
|
38
38
|
for (i = 0; i < numPaths; ++i) {
|
|
39
39
|
var path = paths[i];
|
|
40
|
-
var condition =
|
|
40
|
+
var condition = filter[path];
|
|
41
41
|
if (condition && typeof condition === 'object') {
|
|
42
42
|
var conditionKeys = Object.keys(condition);
|
|
43
43
|
var numConditionKeys = conditionKeys.length;
|
|
@@ -29,6 +29,7 @@ module.exports = function(query, schema, castedDoc, options) {
|
|
|
29
29
|
var numKeys = keys.length;
|
|
30
30
|
var hasDollarUpdate = false;
|
|
31
31
|
var modified = {};
|
|
32
|
+
var currentUpdate;
|
|
32
33
|
|
|
33
34
|
for (var i = 0; i < numKeys; ++i) {
|
|
34
35
|
if (keys[i].charAt(0) === '$') {
|
|
@@ -36,12 +37,13 @@ module.exports = function(query, schema, castedDoc, options) {
|
|
|
36
37
|
keys[i] === '$pull' || keys[i] === '$pullAll') {
|
|
37
38
|
_keys = Object.keys(castedDoc[keys[i]]);
|
|
38
39
|
for (var ii = 0; ii < _keys.length; ++ii) {
|
|
39
|
-
|
|
40
|
+
currentUpdate = castedDoc[keys[i]][_keys[ii]];
|
|
41
|
+
if (currentUpdate && currentUpdate.$each) {
|
|
40
42
|
arrayAtomicUpdates[_keys[ii]] = (arrayAtomicUpdates[_keys[ii]] || []).
|
|
41
|
-
concat(
|
|
43
|
+
concat(currentUpdate.$each);
|
|
42
44
|
} else {
|
|
43
45
|
arrayAtomicUpdates[_keys[ii]] = (arrayAtomicUpdates[_keys[ii]] || []).
|
|
44
|
-
concat([
|
|
46
|
+
concat([currentUpdate]);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
continue;
|
package/lib/types/buffer.js
CHANGED
|
@@ -46,9 +46,18 @@ function MongooseBuffer(value, encode, offset) {
|
|
|
46
46
|
|
|
47
47
|
// make sure these internal props don't show up in Object.keys()
|
|
48
48
|
Object.defineProperties(buf, {
|
|
49
|
-
validators: {
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
validators: {
|
|
50
|
+
value: [],
|
|
51
|
+
enumerable: false
|
|
52
|
+
},
|
|
53
|
+
_path: {
|
|
54
|
+
value: path,
|
|
55
|
+
enumerable: false
|
|
56
|
+
},
|
|
57
|
+
_parent: {
|
|
58
|
+
value: doc,
|
|
59
|
+
enumerable: false
|
|
60
|
+
}
|
|
52
61
|
});
|
|
53
62
|
|
|
54
63
|
if (doc && typeof path === 'string') {
|