mongoose 6.5.2 → 6.5.5

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 (95) hide show
  1. package/.mocharc.yml +2 -0
  2. package/dist/browser.umd.js +1148 -68091
  3. package/lib/aggregate.js +7 -7
  4. package/lib/browserDocument.js +1 -1
  5. package/lib/cast/boolean.js +1 -1
  6. package/lib/cast/number.js +1 -1
  7. package/lib/cast/string.js +1 -1
  8. package/lib/cast.js +3 -0
  9. package/lib/connection.js +19 -11
  10. package/lib/cursor/AggregationCursor.js +16 -5
  11. package/lib/cursor/QueryCursor.js +16 -5
  12. package/lib/document.js +31 -18
  13. package/lib/drivers/browser/objectid.js +2 -1
  14. package/lib/drivers/node-mongodb-native/ReadPreference.js +1 -1
  15. package/lib/drivers/node-mongodb-native/collection.js +6 -2
  16. package/lib/error/browserMissingSchema.js +1 -1
  17. package/lib/error/cast.js +2 -1
  18. package/lib/error/divergentArray.js +2 -1
  19. package/lib/error/missingSchema.js +2 -1
  20. package/lib/error/notFound.js +2 -1
  21. package/lib/error/overwriteModel.js +2 -1
  22. package/lib/error/strictPopulate.js +29 -0
  23. package/lib/error/validation.js +9 -7
  24. package/lib/error/validator.js +8 -4
  25. package/lib/helpers/clone.js +1 -1
  26. package/lib/helpers/discriminator/getConstructor.js +2 -1
  27. package/lib/helpers/discriminator/getDiscriminatorByValue.js +7 -6
  28. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +7 -6
  29. package/lib/helpers/document/compile.js +14 -2
  30. package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +5 -1
  31. package/lib/helpers/get.js +2 -1
  32. package/lib/helpers/getConstructorName.js +2 -1
  33. package/lib/helpers/indexes/isIndexEqual.js +6 -6
  34. package/lib/helpers/isBsonType.js +2 -1
  35. package/lib/helpers/isMongooseObject.js +2 -2
  36. package/lib/helpers/isObject.js +1 -1
  37. package/lib/helpers/isSimpleValidator.js +1 -1
  38. package/lib/helpers/model/applyHooks.js +11 -0
  39. package/lib/helpers/model/applyMethods.js +11 -1
  40. package/lib/helpers/model/applyStatics.js +2 -1
  41. package/lib/helpers/model/castBulkWrite.js +7 -2
  42. package/lib/helpers/model/discriminator.js +3 -1
  43. package/lib/helpers/path/flattenObjectWithDottedPaths.js +3 -2
  44. package/lib/helpers/pluralize.js +1 -1
  45. package/lib/helpers/populate/assignRawDocsToIdStructure.js +5 -3
  46. package/lib/helpers/populate/assignVals.js +14 -3
  47. package/lib/helpers/populate/createPopulateQueryFilter.js +8 -2
  48. package/lib/helpers/populate/getModelsMapForPopulate.js +5 -4
  49. package/lib/helpers/populate/getSchemaTypes.js +3 -1
  50. package/lib/helpers/populate/markArraySubdocsPopulated.js +5 -1
  51. package/lib/helpers/projection/hasIncludedChildren.js +4 -1
  52. package/lib/helpers/projection/isPathExcluded.js +3 -2
  53. package/lib/helpers/projection/isSubpath.js +2 -1
  54. package/lib/helpers/query/applyQueryMiddleware.js +3 -2
  55. package/lib/helpers/query/castUpdate.js +14 -8
  56. package/lib/helpers/query/completeMany.js +3 -2
  57. package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +7 -1
  58. package/lib/helpers/query/wrapThunk.js +3 -1
  59. package/lib/helpers/schema/getIndexes.js +7 -2
  60. package/lib/helpers/schema/getPath.js +4 -3
  61. package/lib/helpers/schema/idGetter.js +2 -1
  62. package/lib/helpers/setDefaultsOnInsert.js +15 -0
  63. package/lib/index.js +20 -12
  64. package/lib/model.js +219 -145
  65. package/lib/query.js +160 -65
  66. package/lib/queryhelpers.js +4 -4
  67. package/lib/schema/SubdocumentPath.js +1 -1
  68. package/lib/schema/array.js +2 -2
  69. package/lib/schema/date.js +2 -1
  70. package/lib/schema/documentarray.js +4 -3
  71. package/lib/schema/operators/helpers.js +2 -2
  72. package/lib/schema/operators/text.js +1 -1
  73. package/lib/schema/string.js +1 -1
  74. package/lib/schema.js +14 -5
  75. package/lib/schematype.js +17 -4
  76. package/lib/statemachine.js +13 -12
  77. package/lib/types/ArraySubdocument.js +13 -3
  78. package/lib/types/DocumentArray/methods/index.js +9 -5
  79. package/lib/types/array/methods/index.js +5 -4
  80. package/lib/types/map.js +3 -1
  81. package/lib/types/objectid.js +2 -2
  82. package/lib/types/subdocument.js +30 -8
  83. package/lib/utils.js +58 -31
  84. package/package.json +11 -11
  85. package/scripts/create-tarball.js +7 -0
  86. package/types/aggregate.d.ts +3 -3
  87. package/types/connection.d.ts +4 -4
  88. package/types/cursor.d.ts +1 -1
  89. package/types/document.d.ts +2 -2
  90. package/types/index.d.ts +13 -27
  91. package/types/indexes.d.ts +2 -2
  92. package/types/middlewares.d.ts +1 -1
  93. package/types/models.d.ts +14 -11
  94. package/types/pipelinestage.d.ts +1 -1
  95. package/types/query.d.ts +33 -16
@@ -41,15 +41,19 @@ class ValidationError extends MongooseError {
41
41
  return this.name + ': ' + _generateMessage(this);
42
42
  }
43
43
 
44
- /*!
44
+ /**
45
45
  * inspect helper
46
+ * @api private
46
47
  */
47
48
  inspect() {
48
49
  return Object.assign(new Error(this.message), this);
49
50
  }
50
51
 
51
- /*!
52
+ /**
52
53
  * add message
54
+ * @param {String} path
55
+ * @param {String|Error} error
56
+ * @api private
53
57
  */
54
58
  addError(path, error) {
55
59
  if (error instanceof ValidationError) {
@@ -68,16 +72,14 @@ class ValidationError extends MongooseError {
68
72
 
69
73
 
70
74
  if (util.inspect.custom) {
71
- /*!
72
- * Avoid Node deprecation warning DEP0079
73
- */
74
-
75
+ // Avoid Node deprecation warning DEP0079
75
76
  ValidationError.prototype[util.inspect.custom] = ValidationError.prototype.inspect;
76
77
  }
77
78
 
78
- /*!
79
+ /**
79
80
  * Helper for JSON.stringify
80
81
  * Ensure `name` and `message` show up in toJSON output re: gh-9847
82
+ * @api private
81
83
  */
82
84
  Object.defineProperty(ValidationError.prototype, 'toJSON', {
83
85
  enumerable: false,
@@ -31,16 +31,18 @@ class ValidatorError extends MongooseError {
31
31
  this.reason = properties.reason;
32
32
  }
33
33
 
34
- /*!
34
+ /**
35
35
  * toString helper
36
36
  * TODO remove? This defaults to `${this.name}: ${this.message}`
37
+ * @api private
37
38
  */
38
39
  toString() {
39
40
  return this.message;
40
41
  }
41
42
 
42
- /*!
43
+ /**
43
44
  * Ensure `name` and `message` show up in toJSON output re: gh-9296
45
+ * @api private
44
46
  */
45
47
 
46
48
  toJSON() {
@@ -53,9 +55,10 @@ Object.defineProperty(ValidatorError.prototype, 'name', {
53
55
  value: 'ValidatorError'
54
56
  });
55
57
 
56
- /*!
58
+ /**
57
59
  * The object used to define this validator. Not enumerable to hide
58
60
  * it from `require('util').inspect()` output re: gh-3925
61
+ * @api private
59
62
  */
60
63
 
61
64
  Object.defineProperty(ValidatorError.prototype, 'properties', {
@@ -67,8 +70,9 @@ Object.defineProperty(ValidatorError.prototype, 'properties', {
67
70
  // Exposed for testing
68
71
  ValidatorError.prototype.formatMessage = formatMessage;
69
72
 
70
- /*!
73
+ /**
71
74
  * Formats error messages
75
+ * @api private
72
76
  */
73
77
 
74
78
  function formatMessage(msg, properties) {
@@ -12,7 +12,7 @@ const trustedSymbol = require('./query/trusted').trustedSymbol;
12
12
  const utils = require('../utils');
13
13
 
14
14
 
15
- /*!
15
+ /**
16
16
  * Object clone with Mongoose natives support.
17
17
  *
18
18
  * If options.minimize is true, creates a minimal data object. Empty objects and undefined values will not be cloned. This makes the data payload sent to MongoDB as small as possible.
@@ -2,8 +2,9 @@
2
2
 
3
3
  const getDiscriminatorByValue = require('./getDiscriminatorByValue');
4
4
 
5
- /*!
5
+ /**
6
6
  * Find the correct constructor, taking into account discriminators
7
+ * @api private
7
8
  */
8
9
 
9
10
  module.exports = function getConstructor(Constructor, value) {
@@ -2,12 +2,13 @@
2
2
 
3
3
  const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
4
4
 
5
- /*!
6
- * returns discriminator by discriminatorMapping.value
7
- *
8
- * @param {Model} model
9
- * @param {string} value
10
- */
5
+ /**
6
+ * returns discriminator by discriminatorMapping.value
7
+ *
8
+ * @param {Object} discriminators
9
+ * @param {string} value
10
+ * @api private
11
+ */
11
12
 
12
13
  module.exports = function getDiscriminatorByValue(discriminators, value) {
13
14
  if (discriminators == null) {
@@ -2,12 +2,13 @@
2
2
 
3
3
  const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
4
4
 
5
- /*!
6
- * returns discriminator by discriminatorMapping.value
7
- *
8
- * @param {Schema} schema
9
- * @param {string} value
10
- */
5
+ /**
6
+ * returns discriminator by discriminatorMapping.value
7
+ *
8
+ * @param {Schema} schema
9
+ * @param {string} value
10
+ * @api private
11
+ */
11
12
 
12
13
  module.exports = function getSchemaDiscriminatorByValue(schema, value) {
13
14
  if (schema == null || schema.discriminators == null) {
@@ -24,8 +24,13 @@ const _isEmptyOptions = Object.freeze({
24
24
  transform: false
25
25
  });
26
26
 
27
- /*!
27
+ /**
28
28
  * Compiles schemas.
29
+ * @param {Object} tree
30
+ * @param {Any} proto
31
+ * @param {String} prefix
32
+ * @param {Object} options
33
+ * @api private
29
34
  */
30
35
 
31
36
  function compile(tree, proto, prefix, options) {
@@ -44,8 +49,15 @@ function compile(tree, proto, prefix, options) {
44
49
  }
45
50
  }
46
51
 
47
- /*!
52
+ /**
48
53
  * Defines the accessor named prop on the incoming prototype.
54
+ * @param {Object} options
55
+ * @param {String} options.prop
56
+ * @param {Boolean} options.subprops
57
+ * @param {Any} options.prototype
58
+ * @param {String} [options.prefix]
59
+ * @param {Object} options.options
60
+ * @api private
49
61
  */
50
62
 
51
63
  function defineKey({ prop, subprops, prototype, prefix, options }) {
@@ -3,9 +3,13 @@
3
3
  const get = require('../get');
4
4
  const getSchemaDiscriminatorByValue = require('../discriminator/getSchemaDiscriminatorByValue');
5
5
 
6
- /*!
6
+ /**
7
7
  * Like `schema.path()`, except with a document, because impossible to
8
8
  * determine path type without knowing the embedded discriminator key.
9
+ * @param {Document} doc
10
+ * @param {String} path
11
+ * @param {Object} [options]
12
+ * @api private
9
13
  */
10
14
 
11
15
  module.exports = function getEmbeddedDiscriminatorPath(doc, path, options) {
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * Simplified lodash.get to work around the annoying null quirk. See:
5
5
  * https://github.com/lodash/lodash/issues/3659
6
+ * @api private
6
7
  */
7
8
 
8
9
  module.exports = function get(obj, path, def) {
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * If `val` is an object, returns constructor name, if possible. Otherwise returns undefined.
5
+ * @api private
5
6
  */
6
7
 
7
8
  module.exports = function getConstructorName(val) {
@@ -6,13 +6,13 @@ const utils = require('../../utils');
6
6
  * Given a Mongoose index definition (key + options objects) and a MongoDB server
7
7
  * index definition, determine if the two indexes are equal.
8
8
  *
9
- * @param {Object} key the Mongoose index spec
9
+ * @param {Object} schemaIndexKeysObject the Mongoose index spec
10
10
  * @param {Object} options the Mongoose index definition's options
11
11
  * @param {Object} dbIndex the index in MongoDB as returned by `listIndexes()`
12
12
  * @api private
13
13
  */
14
14
 
15
- module.exports = function isIndexEqual(key, options, dbIndex) {
15
+ module.exports = function isIndexEqual(schemaIndexKeysObject, options, dbIndex) {
16
16
  // Special case: text indexes have a special format in the db. For example,
17
17
  // `{ name: 'text' }` becomes:
18
18
  // {
@@ -30,11 +30,11 @@ module.exports = function isIndexEqual(key, options, dbIndex) {
30
30
  delete dbIndex.key._fts;
31
31
  delete dbIndex.key._ftsx;
32
32
  const weights = { ...dbIndex.weights, ...dbIndex.key };
33
- if (Object.keys(weights).length !== Object.keys(key).length) {
33
+ if (Object.keys(weights).length !== Object.keys(schemaIndexKeysObject).length) {
34
34
  return false;
35
35
  }
36
36
  for (const prop of Object.keys(weights)) {
37
- if (!(prop in key)) {
37
+ if (!(prop in schemaIndexKeysObject)) {
38
38
  return false;
39
39
  }
40
40
  const weight = weights[prop];
@@ -78,7 +78,7 @@ module.exports = function isIndexEqual(key, options, dbIndex) {
78
78
  }
79
79
  }
80
80
 
81
- const schemaIndexKeys = Object.keys(key);
81
+ const schemaIndexKeys = Object.keys(schemaIndexKeysObject);
82
82
  const dbIndexKeys = Object.keys(dbIndex.key);
83
83
  if (schemaIndexKeys.length !== dbIndexKeys.length) {
84
84
  return false;
@@ -87,7 +87,7 @@ module.exports = function isIndexEqual(key, options, dbIndex) {
87
87
  if (schemaIndexKeys[i] !== dbIndexKeys[i]) {
88
88
  return false;
89
89
  }
90
- if (!utils.deepEqual(key[schemaIndexKeys[i]], dbIndex.key[dbIndexKeys[i]])) {
90
+ if (!utils.deepEqual(schemaIndexKeysObject[schemaIndexKeys[i]], dbIndex.key[dbIndexKeys[i]])) {
91
91
  return false;
92
92
  }
93
93
  }
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * Get the bson type, if it exists
5
+ * @api private
5
6
  */
6
7
 
7
8
  function isBsonType(obj, typename) {
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const isMongooseArray = require('../types/array/isMongooseArray').isMongooseArray;
4
- /*!
4
+ /**
5
5
  * Returns if `v` is a mongoose object that has a `toObject()` method we can use.
6
6
  *
7
7
  * This is for compatibility with libs like Date.js which do foolish things to Natives.
8
8
  *
9
- * @param {any} v
9
+ * @param {Any} v
10
10
  * @api private
11
11
  */
12
12
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * Determines if `arg` is an object.
5
5
  *
6
6
  * @param {Object|Array|String|Function|RegExp|any} arg
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * Determines if `arg` is a flat object.
5
5
  *
6
6
  * @param {Object|Array|String|Function|RegExp|any} arg
@@ -23,10 +23,18 @@ applyHooks.middlewareFunctions = [
23
23
  ];
24
24
 
25
25
  /*!
26
+ * ignore
27
+ */
28
+
29
+ const alreadyHookedFunctions = new Set(applyHooks.middlewareFunctions.flatMap(fn => ([fn, `$__${fn}`])));
30
+
31
+ /**
26
32
  * Register hooks for this model
27
33
  *
28
34
  * @param {Model} model
29
35
  * @param {Schema} schema
36
+ * @param {Object} options
37
+ * @api private
30
38
  */
31
39
 
32
40
  function applyHooks(model, schema, options) {
@@ -115,6 +123,9 @@ function applyHooks(model, schema, options) {
115
123
  checkForPromise: true
116
124
  });
117
125
  for (const method of customMethods) {
126
+ if (alreadyHookedFunctions.has(method)) {
127
+ continue;
128
+ }
118
129
  if (!middleware.hasHooks(method)) {
119
130
  // Don't wrap if there are no hooks for the custom method to avoid
120
131
  // surprises. Also, `createWrapper()` enforces consistent async,
@@ -3,11 +3,12 @@
3
3
  const get = require('../get');
4
4
  const utils = require('../../utils');
5
5
 
6
- /*!
6
+ /**
7
7
  * Register methods for this model
8
8
  *
9
9
  * @param {Model} model
10
10
  * @param {Schema} schema
11
+ * @api private
11
12
  */
12
13
 
13
14
  module.exports = function applyMethods(model, schema) {
@@ -29,6 +30,15 @@ module.exports = function applyMethods(model, schema) {
29
30
  throw new Error('You have a method and a property in your schema both ' +
30
31
  'named "' + method + '"');
31
32
  }
33
+
34
+ // Avoid making custom methods if user sets a method to itself, e.g.
35
+ // `schema.method(save, Document.prototype.save)`. Can happen when
36
+ // calling `loadClass()` with a class that `extends Document`. See gh-12254
37
+ if (typeof fn === 'function' && model.prototype[method] === fn) {
38
+ delete schema.methods[method];
39
+ continue;
40
+ }
41
+
32
42
  if (schema.reserved[method] &&
33
43
  !get(schema, `methodOptions.${method}.suppressWarning`, false)) {
34
44
  utils.warn(`mongoose: the method name "${method}" is used by mongoose ` +
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * Register statics for this model
5
5
  * @param {Model} model
6
6
  * @param {Schema} schema
7
+ * @api private
7
8
  */
8
9
  module.exports = function applyStatics(model, schema) {
9
10
  for (const i in schema.statics) {
@@ -7,9 +7,13 @@ const cast = require('../../cast');
7
7
  const castUpdate = require('../query/castUpdate');
8
8
  const setDefaultsOnInsert = require('../setDefaultsOnInsert');
9
9
 
10
- /*!
10
+ /**
11
11
  * Given a model and a bulkWrite op, return a thunk that handles casting and
12
12
  * validating the individual op.
13
+ * @param {Model} originalModel
14
+ * @param {Object} op
15
+ * @param {Object} [options]
16
+ * @api private
13
17
  */
14
18
 
15
19
  module.exports = function castBulkWrite(originalModel, op, options) {
@@ -222,8 +226,9 @@ function _addDiscriminatorToObject(schema, obj) {
222
226
  }
223
227
  }
224
228
 
225
- /*!
229
+ /**
226
230
  * gets discriminator model if discriminator key is present in object
231
+ * @api private
227
232
  */
228
233
 
229
234
  function decideModelByObject(model, object) {
@@ -9,7 +9,9 @@ const CUSTOMIZABLE_DISCRIMINATOR_OPTIONS = {
9
9
  toJSON: true,
10
10
  toObject: true,
11
11
  _id: true,
12
- id: true
12
+ id: true,
13
+ virtuals: true,
14
+ methods: true
13
15
  };
14
16
 
15
17
  /*!
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const MongooseError = require('../../error/mongooseError');
4
+ const isMongooseObject = require('../isMongooseObject');
4
5
  const setDottedPath = require('../path/setDottedPath');
5
6
  const util = require('util');
6
7
 
@@ -13,8 +14,8 @@ module.exports = function flattenObjectWithDottedPaths(obj) {
13
14
  if (obj == null || typeof obj !== 'object' || Array.isArray(obj)) {
14
15
  return;
15
16
  }
16
- // Avoid Mongoose docs
17
- if (obj.$__) {
17
+ // Avoid Mongoose docs, like docs and maps, because these may cause infinite recursion
18
+ if (isMongooseObject(obj)) {
18
19
  return;
19
20
  }
20
21
  const keys = Object.keys(obj);
@@ -71,7 +71,7 @@ exports.uncountables = [
71
71
  ];
72
72
  const uncountables = exports.uncountables;
73
73
 
74
- /*!
74
+ /**
75
75
  * Pluralize function.
76
76
  *
77
77
  * @author TJ Holowaychuk (extracted from _ext.js_)
@@ -6,7 +6,7 @@ const utils = require('../../utils');
6
6
 
7
7
  module.exports = assignRawDocsToIdStructure;
8
8
 
9
- /*!
9
+ /**
10
10
  * Assign `vals` returned by mongo query to the `rawIds`
11
11
  * structure returned from utils.getVals() honoring
12
12
  * query sort order if specified by user.
@@ -21,8 +21,10 @@ module.exports = assignRawDocsToIdStructure;
21
21
  * else documents are put back in original order of array if found in results
22
22
  *
23
23
  * @param {Array} rawIds
24
- * @param {Array} vals
25
- * @param {Boolean} sort
24
+ * @param {Array} resultDocs
25
+ * @param {Array} resultOrder
26
+ * @param {Object} options
27
+ * @param {Boolean} recursed
26
28
  * @api private
27
29
  */
28
30
 
@@ -212,7 +212,7 @@ function numDocs(v) {
212
212
  return v == null ? 0 : 1;
213
213
  }
214
214
 
215
- /*!
215
+ /**
216
216
  * 1) Apply backwards compatible find/findOne behavior to sub documents
217
217
  *
218
218
  * find logic:
@@ -228,6 +228,12 @@ function numDocs(v) {
228
228
  * background:
229
229
  * _ids are left in the query even when user excludes them so
230
230
  * that population mapping can occur.
231
+ * @param {Any} val
232
+ * @param {Object} assignmentOpts
233
+ * @param {Object} populateOptions
234
+ * @param {Function} [populateOptions.transform]
235
+ * @param {Boolean} allIds
236
+ * @api private
231
237
  */
232
238
 
233
239
  function valueFilter(val, assignmentOpts, populateOptions, allIds) {
@@ -288,8 +294,11 @@ function valueFilter(val, assignmentOpts, populateOptions, allIds) {
288
294
  return val == null ? transform(val, allIds) : transform(null, allIds);
289
295
  }
290
296
 
291
- /*!
297
+ /**
292
298
  * Remove _id from `subdoc` if user specified "lean" query option
299
+ * @param {Document} subdoc
300
+ * @param {Object} assignmentOpts
301
+ * @api private
293
302
  */
294
303
 
295
304
  function maybeRemoveId(subdoc, assignmentOpts) {
@@ -302,9 +311,11 @@ function maybeRemoveId(subdoc, assignmentOpts) {
302
311
  }
303
312
  }
304
313
 
305
- /*!
314
+ /**
306
315
  * Determine if `obj` is something we can set a populated path to. Can be a
307
316
  * document, a lean document, or an array/map that contains docs.
317
+ * @param {Any} obj
318
+ * @api private
308
319
  */
309
320
 
310
321
  function isPopulatedObject(obj) {
@@ -44,9 +44,13 @@ module.exports = function createPopulateQueryFilter(ids, _match, _foreignField,
44
44
  return match;
45
45
  };
46
46
 
47
- /*!
47
+ /**
48
48
  * Optionally filter out invalid ids that don't conform to foreign field's schema
49
49
  * to avoid cast errors (gh-7706)
50
+ * @param {Array} ids
51
+ * @param {SchemaType} foreignSchemaType
52
+ * @param {Boolean} [skipInvalidIds]
53
+ * @api private
50
54
  */
51
55
 
52
56
  function _filterInvalidIds(ids, foreignSchemaType, skipInvalidIds) {
@@ -64,9 +68,11 @@ function _filterInvalidIds(ids, foreignSchemaType, skipInvalidIds) {
64
68
  });
65
69
  }
66
70
 
67
- /*!
71
+ /**
68
72
  * Format `mod.match` given that it may be an array that we need to $or if
69
73
  * the client has multiple docs with match functions
74
+ * @param {Array|Any} match
75
+ * @api private
70
76
  */
71
77
 
72
78
  function _formatMatch(match) {
@@ -15,6 +15,7 @@ const utils = require('../../utils');
15
15
  const modelSymbol = require('../symbols').modelSymbol;
16
16
  const populateModelSymbol = require('../symbols').populateModelSymbol;
17
17
  const schemaMixedSymbol = require('../../schema/symbols').schemaMixedSymbol;
18
+ const StrictPopulate = require('../../error/strictPopulate');
18
19
 
19
20
  module.exports = function getModelsMapForPopulate(model, docs, options) {
20
21
  let doc;
@@ -44,9 +45,7 @@ module.exports = function getModelsMapForPopulate(model, docs, options) {
44
45
  allSchemaTypes = Array.isArray(allSchemaTypes) ? allSchemaTypes : [allSchemaTypes].filter(v => v != null);
45
46
 
46
47
  if (allSchemaTypes.length === 0 && options.strictPopulate !== false && options._localModel != null) {
47
- return new MongooseError('Cannot populate path `' + (options._fullPath || options.path) +
48
- '` because it is not in your schema. Set the `strictPopulate` option ' +
49
- 'to false to override.');
48
+ return new StrictPopulate(options._fullPath || options.path);
50
49
  }
51
50
 
52
51
  for (let i = 0; i < len; i++) {
@@ -625,11 +624,13 @@ function _getLocalFieldValues(doc, localField, model, options, virtual, schema)
625
624
  }
626
625
  }
627
626
 
628
- /*!
627
+ /**
629
628
  * Retrieve the _id of `val` if a Document or Array of Documents.
630
629
  *
631
630
  * @param {Array|Document|Any} val
631
+ * @param {Schema} schema
632
632
  * @return {Array|Document|Any}
633
+ * @api private
633
634
  */
634
635
 
635
636
  function convertTo_id(val, schema) {
@@ -12,15 +12,17 @@ const mpath = require('mpath');
12
12
 
13
13
  const populateModelSymbol = require('../symbols').populateModelSymbol;
14
14
 
15
- /*!
15
+ /**
16
16
  * Given a model and its schema, find all possible schema types for `path`,
17
17
  * including searching through discriminators. If `doc` is specified, will
18
18
  * use the doc's values for discriminator keys when searching, otherwise
19
19
  * will search all discriminators.
20
20
  *
21
+ * @param {Model} model
21
22
  * @param {Schema} schema
22
23
  * @param {Object} doc POJO
23
24
  * @param {string} path
25
+ * @api private
24
26
  */
25
27
 
26
28
  module.exports = function getSchemaTypes(model, schema, doc, path) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  const utils = require('../../utils');
4
4
 
5
- /*!
5
+ /**
6
6
  * If populating a path within a document array, make sure each
7
7
  * subdoc within the array knows its subpaths are populated.
8
8
  *
@@ -10,6 +10,10 @@ const utils = require('../../utils');
10
10
  *
11
11
  * const doc = await Article.findOne().populate('comments.author');
12
12
  * doc.comments[0].populated('author'); // Should be set
13
+ *
14
+ * @param {Document} doc
15
+ * @param {Object} [populated]
16
+ * @api private
13
17
  */
14
18
 
15
19
  module.exports = function markArraySubdocsPopulated(doc, populated) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- /*!
3
+ /**
4
4
  * Creates an object that precomputes whether a given path has child fields in
5
5
  * the projection.
6
6
  *
@@ -11,6 +11,9 @@
11
11
  * res['a.b']; // 1
12
12
  * res['a.b.c']; // 1
13
13
  * res['a.c']; // undefined
14
+ *
15
+ * @param {Object} fields
16
+ * @api private
14
17
  */
15
18
 
16
19
  module.exports = function hasIncludedChildren(fields) {
@@ -2,12 +2,13 @@
2
2
 
3
3
  const isDefiningProjection = require('./isDefiningProjection');
4
4
 
5
- /*!
5
+ /**
6
6
  * Determines if `path` is excluded by `projection`
7
7
  *
8
8
  * @param {Object} projection
9
- * @param {string} path
9
+ * @param {String} path
10
10
  * @return {Boolean}
11
+ * @api private
11
12
  */
12
13
 
13
14
  module.exports = function isPathExcluded(projection, path) {