mongoose 6.3.9 → 6.4.2

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.
Files changed (129) hide show
  1. package/.eslintrc.json +65 -36
  2. package/dist/browser.umd.js +68579 -2
  3. package/lib/cast/date.js +1 -1
  4. package/lib/cast/decimal128.js +1 -1
  5. package/lib/cast/objectid.js +1 -1
  6. package/lib/cast.js +1 -1
  7. package/lib/connection.js +47 -5
  8. package/lib/document.js +48 -8
  9. package/lib/drivers/node-mongodb-native/index.js +1 -1
  10. package/lib/error/parallelValidate.js +1 -1
  11. package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
  12. package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
  13. package/lib/helpers/arrayDepth.js +1 -1
  14. package/lib/helpers/cursor/eachAsync.js +1 -1
  15. package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
  16. package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
  17. package/lib/helpers/discriminator/getConstructor.js +1 -1
  18. package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  19. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
  20. package/lib/helpers/document/handleSpreadDoc.js +1 -1
  21. package/lib/helpers/each.js +1 -1
  22. package/lib/helpers/get.js +1 -1
  23. package/lib/helpers/getConstructorName.js +1 -1
  24. package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
  25. package/lib/helpers/indexes/applySchemaCollation.js +1 -1
  26. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
  27. package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
  28. package/lib/helpers/indexes/isTextIndex.js +1 -1
  29. package/lib/helpers/isMongooseObject.js +1 -1
  30. package/lib/helpers/isObject.js +1 -1
  31. package/lib/helpers/isPromise.js +1 -1
  32. package/lib/helpers/model/applyHooks.js +1 -1
  33. package/lib/helpers/model/applyStaticHooks.js +1 -1
  34. package/lib/helpers/once.js +1 -1
  35. package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
  36. package/lib/helpers/path/parentPaths.js +1 -1
  37. package/lib/helpers/path/setDottedPath.js +1 -1
  38. package/lib/helpers/pluralize.js +1 -1
  39. package/lib/helpers/populate/SkipPopulateValue.js +1 -1
  40. package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
  41. package/lib/helpers/populate/assignVals.js +1 -1
  42. package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
  43. package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
  44. package/lib/helpers/populate/leanPopulateMap.js +1 -1
  45. package/lib/helpers/populate/lookupLocalFields.js +1 -1
  46. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  47. package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
  48. package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
  49. package/lib/helpers/populate/validateRef.js +1 -1
  50. package/lib/helpers/printJestWarning.js +1 -1
  51. package/lib/helpers/processConnectionOptions.js +1 -1
  52. package/lib/helpers/projection/applyProjection.js +1 -1
  53. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  54. package/lib/helpers/projection/parseProjection.js +1 -1
  55. package/lib/helpers/query/applyGlobalOption.js +1 -1
  56. package/lib/helpers/query/applyQueryMiddleware.js +1 -1
  57. package/lib/helpers/query/cast$expr.js +1 -1
  58. package/lib/helpers/query/castFilterPath.js +1 -1
  59. package/lib/helpers/query/sanitizeFilter.js +1 -1
  60. package/lib/helpers/query/sanitizeProjection.js +1 -1
  61. package/lib/helpers/query/trusted.js +1 -1
  62. package/lib/helpers/query/validOps.js +1 -1
  63. package/lib/helpers/query/wrapThunk.js +1 -1
  64. package/lib/helpers/schema/addAutoId.js +1 -1
  65. package/lib/helpers/schema/applyPlugins.js +1 -1
  66. package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
  67. package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
  68. package/lib/helpers/schema/getPath.js +1 -1
  69. package/lib/helpers/schema/handleIdOption.js +1 -1
  70. package/lib/helpers/schema/handleTimestampOption.js +1 -1
  71. package/lib/helpers/specialProperties.js +1 -1
  72. package/lib/helpers/symbols.js +1 -1
  73. package/lib/helpers/timers.js +1 -1
  74. package/lib/helpers/timestamps/setupTimestamps.js +5 -2
  75. package/lib/helpers/topology/allServersUnknown.js +1 -1
  76. package/lib/helpers/topology/isAtlas.js +1 -1
  77. package/lib/helpers/topology/isSSLError.js +1 -1
  78. package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
  79. package/lib/helpers/update/castArrayFilters.js +1 -1
  80. package/lib/helpers/update/moveImmutableProperties.js +1 -1
  81. package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
  82. package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
  83. package/lib/helpers/updateValidators.js +11 -18
  84. package/lib/index.js +108 -29
  85. package/lib/model.js +1 -1
  86. package/lib/options/PopulateOptions.js +1 -1
  87. package/lib/options/SchemaArrayOptions.js +1 -1
  88. package/lib/options/SchemaBufferOptions.js +1 -1
  89. package/lib/options/SchemaDocumentArrayOptions.js +1 -1
  90. package/lib/options/SchemaMapOptions.js +1 -1
  91. package/lib/options/SchemaNumberOptions.js +1 -1
  92. package/lib/options/SchemaObjectIdOptions.js +1 -1
  93. package/lib/options/SchemaSubdocumentOptions.js +1 -1
  94. package/lib/options/SchemaTypeOptions.js +1 -1
  95. package/lib/options/VirtualOptions.js +1 -1
  96. package/lib/options/propertyOptions.js +1 -1
  97. package/lib/options/removeOptions.js +1 -1
  98. package/lib/options/saveOptions.js +1 -1
  99. package/lib/plugins/trackTransaction.js +1 -1
  100. package/lib/query.js +61 -6
  101. package/lib/queryhelpers.js +5 -0
  102. package/lib/schema/array.js +1 -1
  103. package/lib/schema/date.js +2 -2
  104. package/lib/schema/documentarray.js +10 -0
  105. package/lib/schema/number.js +2 -2
  106. package/lib/schema/string.js +2 -2
  107. package/lib/schema/symbols.js +1 -1
  108. package/lib/schema.js +6 -7
  109. package/lib/statemachine.js +13 -0
  110. package/lib/types/DocumentArray/methods/index.js +1 -1
  111. package/lib/utils.js +3 -0
  112. package/lib/validoptions.js +1 -0
  113. package/package.json +3 -3
  114. package/tsconfig.json +1 -0
  115. package/types/collection.d.ts +1 -1
  116. package/types/connection.d.ts +5 -0
  117. package/types/document.d.ts +15 -6
  118. package/types/expressions.d.ts +2882 -0
  119. package/types/index.d.ts +46 -17
  120. package/types/{indizes.d.ts → indexes.d.ts} +2 -2
  121. package/types/inferschematype.d.ts +173 -0
  122. package/types/middlewares.d.ts +1 -1
  123. package/types/models.d.ts +86 -71
  124. package/types/mongooseoptions.d.ts +9 -1
  125. package/types/pipelinestage.d.ts +76 -80
  126. package/types/query.d.ts +1 -1
  127. package/types/schemaoptions.d.ts +22 -4
  128. package/types/types.d.ts +3 -1
  129. package/types/utility.d.ts +9 -0
package/lib/cast/date.js CHANGED
@@ -38,4 +38,4 @@ module.exports = function castDate(value) {
38
38
  }
39
39
 
40
40
  assert.ok(false);
41
- };
41
+ };
@@ -33,4 +33,4 @@ module.exports = function castDecimal128(value) {
33
33
  }
34
34
 
35
35
  assert.ok(false);
36
- };
36
+ };
@@ -26,4 +26,4 @@ module.exports = function castObjectId(value) {
26
26
  }
27
27
 
28
28
  return new ObjectId(value);
29
- };
29
+ };
package/lib/cast.js CHANGED
@@ -374,4 +374,4 @@ function _cast(val, numbertype, context) {
374
374
  }
375
375
  }
376
376
  }
377
- }
377
+ }
package/lib/connection.js CHANGED
@@ -697,6 +697,18 @@ Connection.prototype.openUri = function(uri, options, callback) {
697
697
  typeof callback + '"');
698
698
  }
699
699
 
700
+ if (this._destroyCalled) {
701
+ const error = 'Connection has been closed and destroyed, and cannot be used for re-opening the connection. ' +
702
+ 'Please create a new connection with `mongoose.createConnection()` or `mongoose.connect()`.';
703
+ if (typeof callback === 'function') {
704
+ callback(error);
705
+ return;
706
+ }
707
+ else {
708
+ throw new MongooseError(error);
709
+ }
710
+ }
711
+
700
712
  if (this.readyState === STATES.connecting || this.readyState === STATES.connected) {
701
713
  if (this._connectionString !== uri) {
702
714
  throw new MongooseError('Can\'t call `openUri()` on an active connection with ' +
@@ -901,6 +913,23 @@ function _setClient(conn, client, options, dbName) {
901
913
  }
902
914
  }
903
915
 
916
+ Connection.prototype.destroy = function(force, callback) {
917
+ if (typeof force === 'function') {
918
+ callback = force;
919
+ force = false;
920
+ }
921
+
922
+ if (force != null && typeof force === 'object') {
923
+ this.$wasForceClosed = !!force.force;
924
+ } else {
925
+ this.$wasForceClosed = !!force;
926
+ }
927
+
928
+ return promiseOrCallback(callback, cb => {
929
+ this._close(force, true, cb);
930
+ });
931
+ };
932
+
904
933
  /**
905
934
  * Closes the connection
906
935
  *
@@ -923,7 +952,7 @@ Connection.prototype.close = function(force, callback) {
923
952
  }
924
953
 
925
954
  return promiseOrCallback(callback, cb => {
926
- this._close(force, cb);
955
+ this._close(force, false, cb);
927
956
  });
928
957
  };
929
958
 
@@ -931,19 +960,26 @@ Connection.prototype.close = function(force, callback) {
931
960
  * Handles closing the connection
932
961
  *
933
962
  * @param {Boolean} force
963
+ * @param {Boolean} destroy
934
964
  * @param {Function} callback
935
965
  * @api private
936
966
  */
937
- Connection.prototype._close = function(force, callback) {
967
+ Connection.prototype._close = function(force, destroy, callback) {
938
968
  const _this = this;
939
969
  const closeCalled = this._closeCalled;
940
970
  this._closeCalled = true;
971
+ this._destroyCalled = destroy;
941
972
  if (this.client != null) {
942
973
  this.client._closeCalled = true;
974
+ this.client._destroyCalled = destroy;
943
975
  }
944
976
 
977
+ const conn = this;
945
978
  switch (this.readyState) {
946
979
  case STATES.disconnected:
980
+ if (destroy && this.base.connections.indexOf(conn) !== -1) {
981
+ this.base.connections.splice(this.base.connections.indexOf(conn), 1);
982
+ }
947
983
  if (closeCalled) {
948
984
  callback();
949
985
  } else {
@@ -963,6 +999,9 @@ Connection.prototype._close = function(force, callback) {
963
999
  if (err) {
964
1000
  return callback(err);
965
1001
  }
1002
+ if (destroy && _this.base.connections.indexOf(conn) !== -1) {
1003
+ _this.base.connections.splice(_this.base.connections.indexOf(conn), 1);
1004
+ }
966
1005
  _this.onClose(force);
967
1006
  callback(null);
968
1007
  });
@@ -970,12 +1009,15 @@ Connection.prototype._close = function(force, callback) {
970
1009
  break;
971
1010
  case STATES.connecting:
972
1011
  this.once('open', function() {
973
- _this.close(callback);
1012
+ destroy ? _this.destroy(force, callback) : _this.close(force, callback);
974
1013
  });
975
1014
  break;
976
1015
 
977
1016
  case STATES.disconnecting:
978
1017
  this.once('close', function() {
1018
+ if (destroy && _this.base.connections.indexOf(conn) !== -1) {
1019
+ _this.base.connections.splice(_this.base.connections.indexOf(conn), 1);
1020
+ }
979
1021
  callback();
980
1022
  });
981
1023
  break;
@@ -1004,7 +1046,7 @@ Connection.prototype.onClose = function(force) {
1004
1046
  this.emit('close', force);
1005
1047
 
1006
1048
  for (const db of this.otherDbs) {
1007
- db.close({ force: force, skipCloseClient: true });
1049
+ this._destroyCalled ? db.destroy({ force: force, skipCloseClient: true }) : db.close({ force: force, skipCloseClient: true });
1008
1050
  }
1009
1051
  };
1010
1052
 
@@ -1026,7 +1068,7 @@ Connection.prototype.collection = function(name, options) {
1026
1068
  };
1027
1069
  options = Object.assign({}, defaultOptions, options ? utils.clone(options) : {});
1028
1070
  options.$wasForceClosed = this.$wasForceClosed;
1029
- const Collection = driver.get().Collection;
1071
+ const Collection = this.base && this.base.__driver && this.base.__driver.Collection || driver.get().Collection;
1030
1072
  if (!(name in this.collections)) {
1031
1073
  this.collections[name] = new Collection(name, this, options);
1032
1074
  }
package/lib/document.js CHANGED
@@ -1035,6 +1035,7 @@ Document.prototype.overwrite = function overwrite(obj) {
1035
1035
  * @param {Any} val the value to set
1036
1036
  * @param {Schema|String|Number|Buffer|*} [type] optionally specify a type for "on-the-fly" attributes
1037
1037
  * @param {Object} [options] optionally specify options that modify the behavior of the set
1038
+ * @param {Boolean} [options.merge=false] if true, setting a [nested path](/docs/subdocs.html#subdocuments-versus-nested-paths) will merge existing values rather than overwrite the whole object. So `doc.set('nested', { a: 1, b: 2 })` becomes `doc.set('nested.a', 1); doc.set('nested.b', 2);`
1038
1039
  * @method $set
1039
1040
  * @name $set
1040
1041
  * @memberOf Document
@@ -2486,7 +2487,7 @@ function _getPathsToValidate(doc) {
2486
2487
  const fullPathToSubdoc = subdoc.$__fullPathWithIndexes();
2487
2488
 
2488
2489
  for (const p of paths) {
2489
- if (p === null || p.startsWith(fullPathToSubdoc + '.')) {
2490
+ if (p == null || p.startsWith(fullPathToSubdoc + '.')) {
2490
2491
  paths.delete(p);
2491
2492
  }
2492
2493
  }
@@ -2507,6 +2508,14 @@ function _getPathsToValidate(doc) {
2507
2508
  continue;
2508
2509
  }
2509
2510
 
2511
+ if (_pathType.$isMongooseDocumentArray) {
2512
+ for (const p of paths) {
2513
+ if (p == null || p.startsWith(_pathType.path + '.')) {
2514
+ paths.delete(p);
2515
+ }
2516
+ }
2517
+ }
2518
+
2510
2519
  // Optimization: if primitive path with no validators, or array of primitives
2511
2520
  // with no validators, skip validating this path entirely.
2512
2521
  if (!_pathType.caster && _pathType.validators.length === 0) {
@@ -3145,8 +3154,7 @@ Document.prototype.$__reset = function reset() {
3145
3154
  if (subdoc.$isDocumentArrayElement) {
3146
3155
  if (!resetArrays.has(subdoc.parentArray())) {
3147
3156
  const array = subdoc.parentArray();
3148
- // Mark path to array as init for gh-6818
3149
- this.$__.activePaths.init(fullPathWithIndexes.replace(/\.\d+$/, '').slice(-subdoc.$basePath - 1));
3157
+ this.$__.activePaths.clearPath(fullPathWithIndexes.replace(/\.\d+$/, '').slice(-subdoc.$basePath - 1));
3150
3158
  array[arrayAtomicsBackupSymbol] = array[arrayAtomicsSymbol];
3151
3159
  array[arrayAtomicsSymbol] = {};
3152
3160
 
@@ -3154,7 +3162,7 @@ Document.prototype.$__reset = function reset() {
3154
3162
  }
3155
3163
  } else {
3156
3164
  if (subdoc.$parent() === this) {
3157
- this.$__.activePaths.init(subdoc.$basePath);
3165
+ this.$__.activePaths.clearPath(subdoc.$basePath);
3158
3166
  } else if (subdoc.$parent() != null && subdoc.$parent().$isSubdocument) {
3159
3167
  // If map path underneath subdocument, may end up with a case where
3160
3168
  // map path is modified but parent still needs to be reset. See gh-10295
@@ -4262,10 +4270,10 @@ Document.prototype.$getPopulatedDocs = function $getPopulatedDocs() {
4262
4270
  *
4263
4271
  * #### Example:
4264
4272
  *
4265
- * Model.findOne().populate('author').exec(function (err, doc) {
4266
- * console.log(doc.author.name) // Dr.Seuss
4267
- * console.log(doc.populated('author')) // '5144cf8050f071d979c118a7'
4268
- * })
4273
+ * const doc = await Model.findOne().populate('author');
4274
+ *
4275
+ * console.log(doc.author.name); // Dr.Seuss
4276
+ * console.log(doc.populated('author')); // '5144cf8050f071d979c118a7'
4269
4277
  *
4270
4278
  * If the path was not populated, returns `undefined`.
4271
4279
  *
@@ -4319,6 +4327,38 @@ Document.prototype.populated = function(path, val, options) {
4319
4327
 
4320
4328
  Document.prototype.$populated = Document.prototype.populated;
4321
4329
 
4330
+ /**
4331
+ * Throws an error if a given path is not populated
4332
+ *
4333
+ * #### Example:
4334
+ *
4335
+ * const doc = await Model.findOne().populate('author');
4336
+ *
4337
+ * doc.$assertPopulated('author'); // does not throw
4338
+ * doc.$assertPopulated('other path'); // throws an error
4339
+ *
4340
+ *
4341
+ * @param {String|Array<String>} path
4342
+ * @return {Document} this
4343
+ * @memberOf Document
4344
+ * @method $assertPopulated
4345
+ * @instance
4346
+ * @api public
4347
+ */
4348
+
4349
+ Document.prototype.$assertPopulated = function $assertPopulated(paths) {
4350
+ if (Array.isArray(paths)) {
4351
+ paths.forEach(path => this.$assertPopulated(path));
4352
+ return this;
4353
+ }
4354
+
4355
+ if (!this.$populated(paths)) {
4356
+ throw new MongooseError(`Expected path "${paths}" to be populated`);
4357
+ }
4358
+
4359
+ return this;
4360
+ };
4361
+
4322
4362
  /**
4323
4363
  * Takes a populated field and returns it to its unpopulated state.
4324
4364
  *
@@ -9,4 +9,4 @@ exports.Collection = require('./collection');
9
9
  exports.Decimal128 = require('./decimal128');
10
10
  exports.ObjectId = require('./objectid');
11
11
  exports.ReadPreference = require('./ReadPreference');
12
- exports.getConnection = () => require('./connection');
12
+ exports.getConnection = () => require('./connection');
@@ -28,4 +28,4 @@ Object.defineProperty(ParallelValidateError.prototype, 'name', {
28
28
  * exports
29
29
  */
30
30
 
31
- module.exports = ParallelValidateError;
31
+ module.exports = ParallelValidateError;
@@ -34,4 +34,4 @@ module.exports = function prepareDiscriminatorPipeline(pipeline, schema, prefix)
34
34
  originalPipeline.unshift({ $match: match });
35
35
  }
36
36
  }
37
- };
37
+ };
@@ -47,4 +47,4 @@ function handleAccumulator(operator) {
47
47
  operator.$accumulator[key] = String(operator.$accumulator[key]);
48
48
  }
49
49
  }
50
- }
50
+ }
@@ -30,4 +30,4 @@ function arrayDepth(arr) {
30
30
  res.max = res.max + 1;
31
31
 
32
32
  return res;
33
- }
33
+ }
@@ -189,4 +189,4 @@ function createEachAsyncMultiError(aggregatedErrors) {
189
189
  }
190
190
 
191
191
  return new EachAsyncMultiError(aggregatedErrors);
192
- }
192
+ }
@@ -13,4 +13,4 @@ module.exports = function areDiscriminatorValuesEqual(a, b) {
13
13
  return a.toString() === b.toString();
14
14
  }
15
15
  return false;
16
- };
16
+ };
@@ -9,4 +9,4 @@ module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection
9
9
  addedPaths[0] === _discriminatorKey) {
10
10
  selected.splice(selected.indexOf(_discriminatorKey), 1);
11
11
  }
12
- };
12
+ };
@@ -22,4 +22,4 @@ module.exports = function getConstructor(Constructor, value) {
22
22
  }
23
23
 
24
24
  return Constructor;
25
- };
25
+ };
@@ -24,4 +24,4 @@ module.exports = function getDiscriminatorByValue(discriminators, value) {
24
24
  }
25
25
  }
26
26
  return null;
27
- };
27
+ };
@@ -23,4 +23,4 @@ module.exports = function getSchemaDiscriminatorByValue(schema, value) {
23
23
  }
24
24
  }
25
25
  return null;
26
- };
26
+ };
@@ -32,4 +32,4 @@ module.exports = function handleSpreadDoc(v, includeExtraKeys) {
32
32
  }
33
33
 
34
34
  return v;
35
- };
35
+ };
@@ -22,4 +22,4 @@ module.exports = function each(arr, cb, done) {
22
22
  }
23
23
  });
24
24
  }
25
- };
25
+ };
@@ -61,4 +61,4 @@ function getProperty(obj, prop) {
61
61
  return obj.get(prop);
62
62
  }
63
63
  return obj[prop];
64
- }
64
+ }
@@ -12,4 +12,4 @@ module.exports = function getConstructorName(val) {
12
12
  return void 0;
13
13
  }
14
14
  return val.constructor.name;
15
- };
15
+ };
@@ -24,4 +24,4 @@ function getDefaultBulkwriteResult() {
24
24
  };
25
25
  }
26
26
 
27
- module.exports = getDefaultBulkwriteResult;
27
+ module.exports = getDefaultBulkwriteResult;
@@ -10,4 +10,4 @@ module.exports = function applySchemaCollation(indexKeys, indexOptions, schemaOp
10
10
  if (schemaOptions.hasOwnProperty('collation') && !indexOptions.hasOwnProperty('collation')) {
11
11
  indexOptions.collation = schemaOptions.collation;
12
12
  }
13
- };
13
+ };
@@ -11,4 +11,4 @@ module.exports = function decorateDiscriminatorIndexOptions(schema, indexOptions
11
11
  indexOptions.partialFilterExpression[discriminatorKey] = discriminatorName;
12
12
  }
13
13
  return indexOptions;
14
- };
14
+ };
@@ -15,4 +15,4 @@ module.exports = function isDefaultIdIndex(index) {
15
15
 
16
16
  const key = get(index, 'key', {});
17
17
  return Object.keys(key).length === 1 && key.hasOwnProperty('_id');
18
- };
18
+ };
@@ -13,4 +13,4 @@ module.exports = function isTextIndex(indexKeys) {
13
13
  }
14
14
 
15
15
  return isTextIndex;
16
- };
16
+ };
@@ -19,4 +19,4 @@ module.exports = function(v) {
19
19
  v.$isMongooseMap // Map
20
20
  )
21
21
  );
22
- };
22
+ };
@@ -13,4 +13,4 @@ module.exports = function(arg) {
13
13
  Buffer.isBuffer(arg) ||
14
14
  Object.prototype.toString.call(arg) === '[object Object]'
15
15
  );
16
- };
16
+ };
@@ -3,4 +3,4 @@ function isPromise(val) {
3
3
  return !!val && (typeof val === 'object' || typeof val === 'function') && typeof val.then === 'function';
4
4
  }
5
5
 
6
- module.exports = isPromise;
6
+ module.exports = isPromise;
@@ -135,4 +135,4 @@ function applyHooks(model, schema, options) {
135
135
  objToDecorate[`$__${method}`] = middleware.
136
136
  createWrapper(method, originalMethod, null, customMethodOptions);
137
137
  }
138
- }
138
+ }
@@ -68,4 +68,4 @@ module.exports = function applyStaticHooks(model, hooks, statics) {
68
68
  };
69
69
  }
70
70
  }
71
- };
71
+ };
@@ -9,4 +9,4 @@ module.exports = function once(fn) {
9
9
  called = true;
10
10
  return fn.apply(null, arguments);
11
11
  };
12
- };
12
+ };
@@ -35,4 +35,4 @@ module.exports = function flattenObjectWithDottedPaths(obj) {
35
35
 
36
36
  flattenObjectWithDottedPaths(obj[key]);
37
37
  }
38
- };
38
+ };
@@ -15,4 +15,4 @@ module.exports = function parentPaths(path) {
15
15
  }
16
16
 
17
17
  return ret;
18
- };
18
+ };
@@ -30,4 +30,4 @@ module.exports = function setDottedPath(obj, path, val) {
30
30
  if (!specialProperties.has(last)) {
31
31
  cur[last] = val;
32
32
  }
33
- };
33
+ };
@@ -91,4 +91,4 @@ function pluralize(str) {
91
91
  }
92
92
  }
93
93
  return str;
94
- }
94
+ }
@@ -7,4 +7,4 @@ module.exports = function SkipPopulateValue(val) {
7
7
 
8
8
  this.val = val;
9
9
  return this;
10
- };
10
+ };
@@ -106,4 +106,4 @@ function assignRawDocsToIdStructure(rawIds, resultDocs, resultOrder, options, re
106
106
  rawIds[i] = doc;
107
107
  });
108
108
  }
109
- }
109
+ }
@@ -320,4 +320,4 @@ function isPopulatedObject(obj) {
320
320
 
321
321
  function noop(v) {
322
322
  return v;
323
- }
323
+ }
@@ -77,4 +77,4 @@ function _formatMatch(match) {
77
77
  return Object.assign({}, match[0]);
78
78
  }
79
79
  return Object.assign({}, match);
80
- }
80
+ }
@@ -726,4 +726,4 @@ function _findRefPathForDiscriminators(doc, modelSchema, data, options, normaliz
726
726
  }
727
727
 
728
728
  return modelNames;
729
- }
729
+ }
@@ -4,4 +4,4 @@
4
4
  * ignore
5
5
  */
6
6
 
7
- module.exports = new WeakMap();
7
+ module.exports = new WeakMap();
@@ -37,4 +37,4 @@ module.exports = function lookupLocalFields(cur, path, val) {
37
37
  }
38
38
 
39
39
  return cur[path];
40
- };
40
+ };
@@ -39,4 +39,4 @@ module.exports = function markArraySubdocsPopulated(doc, populated) {
39
39
  }
40
40
  }
41
41
  }
42
- };
42
+ };
@@ -65,4 +65,4 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod
65
65
  modelNames = utils.array.flatten(modelNames);
66
66
 
67
67
  return modelNames;
68
- };
68
+ };
@@ -28,4 +28,4 @@ module.exports = function removeDeselectedForeignField(foreignFields, options, d
28
28
  }
29
29
  }
30
30
  }
31
- };
31
+ };
@@ -16,4 +16,4 @@ function validateRef(ref, path) {
16
16
 
17
17
  throw new MongooseError('Invalid ref at path "' + path + '". Got ' +
18
18
  util.inspect(ref, { depth: 0 }));
19
- }
19
+ }
@@ -14,4 +14,4 @@ if (typeof jest !== 'undefined' && process.nextTick.toString().indexOf('nextTick
14
14
  'with Jest\'s mock timers enabled. Please make sure you read ' +
15
15
  'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
16
16
  'https://mongoosejs.com/docs/jest.html');
17
- }
17
+ }
@@ -9,7 +9,7 @@ function processConnectionOptions(uri, options) {
9
9
  ? opts.readPreference
10
10
  : getUriReadPreference(uri);
11
11
 
12
- const resolvedOpts = (readPreference && readPreference !== 'primary')
12
+ const resolvedOpts = (readPreference && readPreference !== 'primary' && readPreference !== 'primaryPreferred')
13
13
  ? resolveOptsConflicts(readPreference, opts)
14
14
  : opts;
15
15
 
@@ -74,4 +74,4 @@ function applyInclusiveProjection(doc, projection, hasIncludedChildren, projecti
74
74
  }
75
75
  }
76
76
  return ret;
77
- }
77
+ }
@@ -33,4 +33,4 @@ module.exports = function hasIncludedChildren(fields) {
33
33
  }
34
34
 
35
35
  return hasIncludedChildren;
36
- };
36
+ };
@@ -30,4 +30,4 @@ module.exports = function parseProjection(v, retainMinusPaths) {
30
30
  }
31
31
 
32
32
  return ret;
33
- };
33
+ };
@@ -26,4 +26,4 @@ function applyGlobalOption(options, model, optionName) {
26
26
  } else if (utils.hasUserDefinedProperty(model.base.options, optionName)) {
27
27
  options[optionName] = model.base.options[optionName];
28
28
  }
29
- }
29
+ }
@@ -75,4 +75,4 @@ function _getContexts(hook) {
75
75
  ret.document = hook.document;
76
76
  }
77
77
  return ret;
78
- }
78
+ }
@@ -279,4 +279,4 @@ function isLiteral(val) {
279
279
  return val.$literal != null;
280
280
  }
281
281
  return true;
282
- }
282
+ }
@@ -51,4 +51,4 @@ module.exports = function castFilterPath(query, schematype, val) {
51
51
  }
52
52
 
53
53
  return val;
54
- };
54
+ };
@@ -35,4 +35,4 @@ module.exports = function sanitizeFilter(filter) {
35
35
  }
36
36
 
37
37
  return filter;
38
- };
38
+ };
@@ -11,4 +11,4 @@ module.exports = function sanitizeProjection(projection) {
11
11
  projection[keys[i]] = 1;
12
12
  }
13
13
  }
14
- };
14
+ };
@@ -10,4 +10,4 @@ exports.trusted = function trusted(obj) {
10
10
  }
11
11
  obj[trustedSymbol] = true;
12
12
  return obj;
13
- };
13
+ };
@@ -21,4 +21,4 @@ module.exports = Object.freeze([
21
21
  'findOneAndDelete',
22
22
  'findOneAndRemove',
23
23
  'remove'
24
- ]);
24
+ ]);