mongoose 6.4.4 → 6.4.7

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/lib/query.js CHANGED
@@ -2133,7 +2133,7 @@ Query.prototype._unsetCastError = function _unsetCastError() {
2133
2133
  * Below are the current Mongoose-specific options.
2134
2134
  *
2135
2135
  * - `populate`: an array representing what paths will be populated. Should have one entry for each call to [`Query.prototype.populate()`](/docs/api.html#query_Query-populate)
2136
- * - `lean`: if truthy, Mongoose will not [hydrate](/docs/api.html#model_Model.hydrate) any documents that are returned from this query. See [`Query.prototype.lean()`](/docs/api.html#query_Query-lean) for more information.
2136
+ * - `lean`: if truthy, Mongoose will not [hydrate](/docs/api.html#model_Model-hydrate) any documents that are returned from this query. See [`Query.prototype.lean()`](/docs/api.html#query_Query-lean) for more information.
2137
2137
  * - `strict`: controls how Mongoose handles keys that aren't in the schema for updates. This option is `true` by default, which means Mongoose will silently strip any paths in the update that aren't in the schema. See the [`strict` mode docs](/docs/guide.html#strict) for more information.
2138
2138
  * - `strictQuery`: controls how Mongoose handles keys that aren't in the schema for the query `filter`. This option is `false` by default for backwards compatibility, which means Mongoose will allow `Model.find({ foo: 'bar' })` even if `foo` is not in the schema. See the [`strictQuery` docs](/docs/guide.html#strictQuery) for more information.
2139
2139
  * - `nearSphere`: use `$nearSphere` instead of `near()`. See the [`Query.prototype.nearSphere()` docs](/docs/api.html#query_Query-nearSphere)
@@ -4019,7 +4019,9 @@ Query.prototype._findAndModify = function(type, callback) {
4019
4019
  */
4020
4020
 
4021
4021
  function _completeOneLean(schema, doc, path, res, opts, callback) {
4022
- if (opts.lean && opts.lean.transform) {
4022
+ if (opts.lean && typeof opts.lean.transform === 'function') {
4023
+ opts.lean.transform(doc);
4024
+
4023
4025
  for (let i = 0; i < schema.childSchemas.length; i++) {
4024
4026
  const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path;
4025
4027
  const _schema = schema.childSchemas[i].schema;
@@ -4053,7 +4055,11 @@ function _completeOneLean(schema, doc, path, res, opts, callback) {
4053
4055
  */
4054
4056
 
4055
4057
  function _completeManyLean(schema, docs, path, opts, callback) {
4056
- if (opts.lean && opts.lean.transform) {
4058
+ if (opts.lean && typeof opts.lean.transform === 'function') {
4059
+ for (const doc of docs) {
4060
+ opts.lean.transform(doc);
4061
+ }
4062
+
4057
4063
  for (let i = 0; i < schema.childSchemas.length; i++) {
4058
4064
  const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path;
4059
4065
  const _schema = schema.childSchemas[i].schema;
@@ -4239,7 +4245,7 @@ Query.prototype.validate = function validate(castedDoc, options, isOverwriting,
4239
4245
  * Internal thunk for .update()
4240
4246
  *
4241
4247
  * @param {Function} callback
4242
- * @see Model.update #model_Model.update
4248
+ * @see Model.update #model_Model-update
4243
4249
  * @api private
4244
4250
  */
4245
4251
  Query.prototype._execUpdate = wrapThunk(function(callback) {
@@ -4250,7 +4256,7 @@ Query.prototype._execUpdate = wrapThunk(function(callback) {
4250
4256
  * Internal thunk for .updateMany()
4251
4257
  *
4252
4258
  * @param {Function} callback
4253
- * @see Model.update #model_Model.update
4259
+ * @see Model.update #model_Model-update
4254
4260
  * @api private
4255
4261
  */
4256
4262
  Query.prototype._updateMany = wrapThunk(function(callback) {
@@ -4261,7 +4267,7 @@ Query.prototype._updateMany = wrapThunk(function(callback) {
4261
4267
  * Internal thunk for .updateOne()
4262
4268
  *
4263
4269
  * @param {Function} callback
4264
- * @see Model.update #model_Model.update
4270
+ * @see Model.update #model_Model-update
4265
4271
  * @api private
4266
4272
  */
4267
4273
  Query.prototype._updateOne = wrapThunk(function(callback) {
@@ -4272,7 +4278,7 @@ Query.prototype._updateOne = wrapThunk(function(callback) {
4272
4278
  * Internal thunk for .replaceOne()
4273
4279
  *
4274
4280
  * @param {Function} callback
4275
- * @see Model.replaceOne #model_Model.replaceOne
4281
+ * @see Model.replaceOne #model_Model-replaceOne
4276
4282
  * @api private
4277
4283
  */
4278
4284
  Query.prototype._replaceOne = wrapThunk(function(callback) {
@@ -4362,7 +4368,7 @@ Query.prototype._replaceOne = wrapThunk(function(callback) {
4362
4368
  * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4363
4369
  * @param {Function} [callback] params are (error, writeOpResult)
4364
4370
  * @return {Query} this
4365
- * @see Model.update #model_Model.update
4371
+ * @see Model.update #model_Model-update
4366
4372
  * @see Query docs https://mongoosejs.com/docs/queries.html
4367
4373
  * @see update https://docs.mongodb.org/manual/reference/method/db.collection.update/
4368
4374
  * @see writeOpResult https://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#~WriteOpResult
@@ -4426,7 +4432,7 @@ Query.prototype.update = function(conditions, doc, options, callback) {
4426
4432
  * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4427
4433
  * @param {Function} [callback] params are (error, writeOpResult)
4428
4434
  * @return {Query} this
4429
- * @see Model.update #model_Model.update
4435
+ * @see Model.update #model_Model-update
4430
4436
  * @see Query docs https://mongoosejs.com/docs/queries.html
4431
4437
  * @see update https://docs.mongodb.org/manual/reference/method/db.collection.update/
4432
4438
  * @see writeOpResult https://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#~WriteOpResult
@@ -4491,7 +4497,7 @@ Query.prototype.updateMany = function(conditions, doc, options, callback) {
4491
4497
  * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
4492
4498
  * @param {Function} [callback] params are (error, writeOpResult)
4493
4499
  * @return {Query} this
4494
- * @see Model.update #model_Model.update
4500
+ * @see Model.update #model_Model-update
4495
4501
  * @see Query docs https://mongoosejs.com/docs/queries.html
4496
4502
  * @see update https://docs.mongodb.org/manual/reference/method/db.collection.update/
4497
4503
  * @see writeOpResult https://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#~WriteOpResult
@@ -4554,7 +4560,7 @@ Query.prototype.updateOne = function(conditions, doc, options, callback) {
4554
4560
  * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4555
4561
  * @param {Function} [callback] params are (error, writeOpResult)
4556
4562
  * @return {Query} this
4557
- * @see Model.update #model_Model.update
4563
+ * @see Model.update #model_Model-update
4558
4564
  * @see Query docs https://mongoosejs.com/docs/queries.html
4559
4565
  * @see update https://docs.mongodb.org/manual/reference/method/db.collection.update/
4560
4566
  * @see writeOpResult https://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#~WriteOpResult
@@ -5055,7 +5061,7 @@ function castQuery(query) {
5055
5061
  * @param {Object} [options.options=null] Additional options like `limit` and `lean`.
5056
5062
  * @see population ./populate.html
5057
5063
  * @see Query#select #query_Query-select
5058
- * @see Model.populate #model_Model.populate
5064
+ * @see Model.populate #model_Model-populate
5059
5065
  * @return {Query} this
5060
5066
  * @api public
5061
5067
  */
package/lib/schema.js CHANGED
@@ -554,6 +554,10 @@ Schema.prototype.add = function add(obj, prefix) {
554
554
  const keys = Object.keys(obj);
555
555
  const typeKey = this.options.typeKey;
556
556
  for (const key of keys) {
557
+ if (utils.specialProperties.has(key)) {
558
+ continue;
559
+ }
560
+
557
561
  const fullPath = prefix + key;
558
562
  const val = obj[key];
559
563
 
@@ -854,6 +858,9 @@ Schema.prototype.path = function(path, obj) {
854
858
  let fullPath = '';
855
859
 
856
860
  for (const sub of subpaths) {
861
+ if (utils.specialProperties.has(sub)) {
862
+ throw new Error('Cannot set special property `' + sub + '` on a schema');
863
+ }
857
864
  fullPath = fullPath += (fullPath.length > 0 ? '.' : '') + sub;
858
865
  if (!branch[sub]) {
859
866
  this.nested[fullPath] = true;
@@ -1691,7 +1698,7 @@ Schema.prototype.post = function(name) {
1691
1698
  *
1692
1699
  * @param {Function} plugin The Plugin's callback
1693
1700
  * @param {Object} [opts] Options to pass to the plugin
1694
- * @see plugins
1701
+ * @see plugins /docs/plugins.html
1695
1702
  * @api public
1696
1703
  */
1697
1704
 
package/lib/schematype.js CHANGED
@@ -134,6 +134,7 @@ SchemaType.prototype.OptionsConstructor = SchemaTypeOptions;
134
134
  * The path to this SchemaType in a Schema.
135
135
  *
136
136
  * #### Example:
137
+ *
137
138
  * const schema = new Schema({ name: String });
138
139
  * schema.path('name').path; // 'name'
139
140
  *
@@ -148,6 +149,7 @@ SchemaType.prototype.path;
148
149
  * The validators that Mongoose should run to validate properties at this SchemaType's path.
149
150
  *
150
151
  * #### Example:
152
+ *
151
153
  * const schema = new Schema({ name: { type: String, required: true } });
152
154
  * schema.path('name').validators.length; // 1, the `required` validator
153
155
  *
@@ -162,6 +164,7 @@ SchemaType.prototype.validators;
162
164
  * True if this SchemaType has a required validator. False otherwise.
163
165
  *
164
166
  * #### Example:
167
+ *
165
168
  * const schema = new Schema({ name: { type: String, required: true } });
166
169
  * schema.path('name').isRequired; // true
167
170
  *
@@ -175,8 +178,11 @@ SchemaType.prototype.validators;
175
178
 
176
179
  SchemaType.prototype.validators;
177
180
 
178
- /*!
179
- * ignore
181
+ /**
182
+ * Split the current dottet path into segments
183
+ *
184
+ * @return {String[]|undefined}
185
+ * @api private
180
186
  */
181
187
 
182
188
  SchemaType.prototype.splitPath = function() {
@@ -351,8 +357,8 @@ SchemaType.get = function(getter) {
351
357
  * const m2 = new M;
352
358
  * console.log(m2.mixed); // { added: 1 }
353
359
  *
354
- * @param {Function|any} val the default value
355
- * @return {defaultValue}
360
+ * @param {Function|any} val The default value to set
361
+ * @return {Any|undefined} Returns the set default value.
356
362
  * @api public
357
363
  */
358
364
 
@@ -414,7 +420,7 @@ SchemaType.prototype.index = function(options) {
414
420
  *
415
421
  * #### Example:
416
422
  *
417
- * const s = new Schema({ name: { type: String, unique: true }});
423
+ * const s = new Schema({ name: { type: String, unique: true } });
418
424
  * s.path('name').index({ unique: true });
419
425
  *
420
426
  * _NOTE: violating the constraint returns an `E11000` error from MongoDB when saving, not a Mongoose validation error._
@@ -452,8 +458,9 @@ SchemaType.prototype.unique = function(bool) {
452
458
  *
453
459
  * ### Example:
454
460
  *
455
- * const s = new Schema({name : {type: String, text : true })
456
- * s.path('name').index({text : true});
461
+ * const s = new Schema({ name : { type: String, text : true } })
462
+ * s.path('name').index({ text : true });
463
+ *
457
464
  * @param {Boolean} bool
458
465
  * @return {SchemaType} this
459
466
  * @api public
@@ -462,7 +469,7 @@ SchemaType.prototype.unique = function(bool) {
462
469
  SchemaType.prototype.text = function(bool) {
463
470
  if (this._index === false) {
464
471
  if (!bool) {
465
- return;
472
+ return this;
466
473
  }
467
474
  throw new Error('Path "' + this.path + '" may not have `index` set to ' +
468
475
  'false and `text` set to true');
@@ -499,7 +506,7 @@ SchemaType.prototype.text = function(bool) {
499
506
  SchemaType.prototype.sparse = function(bool) {
500
507
  if (this._index === false) {
501
508
  if (!bool) {
502
- return;
509
+ return this;
503
510
  }
504
511
  throw new Error('Path "' + this.path + '" may not have `index` set to ' +
505
512
  'false and `sparse` set to true');
@@ -606,19 +613,17 @@ SchemaType.prototype.transform = function(fn) {
606
613
  *
607
614
  * #### Example:
608
615
  *
609
- * ```javascript
610
- * function capitalize (val) {
611
- * if (typeof val !== 'string') val = '';
612
- * return val.charAt(0).toUpperCase() + val.substring(1);
613
- * }
616
+ * function capitalize (val) {
617
+ * if (typeof val !== 'string') val = '';
618
+ * return val.charAt(0).toUpperCase() + val.substring(1);
619
+ * }
614
620
  *
615
- * // defining within the schema
616
- * const s = new Schema({ name: { type: String, set: capitalize }});
621
+ * // defining within the schema
622
+ * const s = new Schema({ name: { type: String, set: capitalize }});
617
623
  *
618
- * // or with the SchemaType
619
- * const s = new Schema({ name: String })
620
- * s.path('name').set(capitalize);
621
- * ```
624
+ * // or with the SchemaType
625
+ * const s = new Schema({ name: String })
626
+ * s.path('name').set(capitalize);
622
627
  *
623
628
  * Setters allow you to transform the data before it gets to the raw mongodb
624
629
  * document or query.
@@ -630,76 +635,68 @@ SchemaType.prototype.transform = function(fn) {
630
635
  *
631
636
  * You can set up email lower case normalization easily via a Mongoose setter.
632
637
  *
633
- * ```javascript
634
- * function toLower(v) {
635
- * return v.toLowerCase();
636
- * }
638
+ * function toLower(v) {
639
+ * return v.toLowerCase();
640
+ * }
637
641
  *
638
- * const UserSchema = new Schema({
639
- * email: { type: String, set: toLower }
640
- * });
642
+ * const UserSchema = new Schema({
643
+ * email: { type: String, set: toLower }
644
+ * });
641
645
  *
642
- * const User = db.model('User', UserSchema);
646
+ * const User = db.model('User', UserSchema);
643
647
  *
644
- * const user = new User({email: 'AVENUE@Q.COM'});
645
- * console.log(user.email); // 'avenue@q.com'
648
+ * const user = new User({email: 'AVENUE@Q.COM'});
649
+ * console.log(user.email); // 'avenue@q.com'
646
650
  *
647
- * // or
648
- * const user = new User();
649
- * user.email = 'Avenue@Q.com';
650
- * console.log(user.email); // 'avenue@q.com'
651
- * User.updateOne({ _id: _id }, { $set: { email: 'AVENUE@Q.COM' } }); // update to 'avenue@q.com'
652
- * ```
651
+ * // or
652
+ * const user = new User();
653
+ * user.email = 'Avenue@Q.com';
654
+ * console.log(user.email); // 'avenue@q.com'
655
+ * User.updateOne({ _id: _id }, { $set: { email: 'AVENUE@Q.COM' } }); // update to 'avenue@q.com'
653
656
  *
654
657
  * As you can see above, setters allow you to transform the data before it
655
658
  * stored in MongoDB, or before executing a query.
656
659
  *
657
660
  * _NOTE: we could have also just used the built-in `lowercase: true` SchemaType option instead of defining our own function._
658
661
  *
659
- * ```javascript
660
- * new Schema({ email: { type: String, lowercase: true }})
661
- * ```
662
+ * new Schema({ email: { type: String, lowercase: true }})
662
663
  *
663
664
  * Setters are also passed a second argument, the schematype on which the setter was defined. This allows for tailored behavior based on options passed in the schema.
664
665
  *
665
- * ```javascript
666
- * function inspector (val, priorValue, schematype) {
667
- * if (schematype.options.required) {
668
- * return schematype.path + ' is required';
669
- * } else {
670
- * return val;
671
- * }
672
- * }
666
+ * function inspector (val, priorValue, schematype) {
667
+ * if (schematype.options.required) {
668
+ * return schematype.path + ' is required';
669
+ * } else {
670
+ * return val;
671
+ * }
672
+ * }
673
673
  *
674
- * const VirusSchema = new Schema({
675
- * name: { type: String, required: true, set: inspector },
676
- * taxonomy: { type: String, set: inspector }
677
- * })
674
+ * const VirusSchema = new Schema({
675
+ * name: { type: String, required: true, set: inspector },
676
+ * taxonomy: { type: String, set: inspector }
677
+ * })
678
678
  *
679
- * const Virus = db.model('Virus', VirusSchema);
680
- * const v = new Virus({ name: 'Parvoviridae', taxonomy: 'Parvovirinae' });
679
+ * const Virus = db.model('Virus', VirusSchema);
680
+ * const v = new Virus({ name: 'Parvoviridae', taxonomy: 'Parvovirinae' });
681
681
  *
682
- * console.log(v.name); // name is required
683
- * console.log(v.taxonomy); // Parvovirinae
684
- * ```
682
+ * console.log(v.name); // name is required
683
+ * console.log(v.taxonomy); // Parvovirinae
685
684
  *
686
685
  * You can also use setters to modify other properties on the document. If
687
686
  * you're setting a property `name` on a document, the setter will run with
688
687
  * `this` as the document. Be careful, in mongoose 5 setters will also run
689
688
  * when querying by `name` with `this` as the query.
690
689
  *
691
- * ```javascript
692
- * const nameSchema = new Schema({ name: String, keywords: [String] });
693
- * nameSchema.path('name').set(function(v) {
694
- * // Need to check if `this` is a document, because in mongoose 5
695
- * // setters will also run on queries, in which case `this` will be a
696
- * // mongoose query object.
697
- * if (this instanceof Document && v != null) {
698
- * this.keywords = v.split(' ');
699
- * }
700
- * return v;
701
- * });
702
- * ```
690
+ * const nameSchema = new Schema({ name: String, keywords: [String] });
691
+ * nameSchema.path('name').set(function(v) {
692
+ * // Need to check if `this` is a document, because in mongoose 5
693
+ * // setters will also run on queries, in which case `this` will be a
694
+ * // mongoose query object.
695
+ * if (this instanceof Document && v != null) {
696
+ * this.keywords = v.split(' ');
697
+ * }
698
+ * return v;
699
+ * });
703
700
  *
704
701
  * @param {Function} fn
705
702
  * @return {SchemaType} this
@@ -824,7 +821,7 @@ SchemaType.prototype.get = function(fn) {
824
821
  * From the examples above, you may have noticed that error messages support
825
822
  * basic templating. There are a few other template keywords besides `{PATH}`
826
823
  * and `{VALUE}` too. To find out more, details are available
827
- * [here](#error_messages_MongooseError.messages).
824
+ * [here](#error_messages_MongooseError-messages).
828
825
  *
829
826
  * If Mongoose's built-in error message templating isn't enough, Mongoose
830
827
  * supports setting the `message` property to a function.
@@ -993,9 +990,9 @@ SchemaType.prototype.validate = function(obj, message, type) {
993
990
  * @param {String} [message] optional custom error message
994
991
  * @return {SchemaType} this
995
992
  * @see Customized Error Messages #error_messages_MongooseError-messages
996
- * @see SchemaArray#checkRequired #schema_array_SchemaArray.checkRequired
993
+ * @see SchemaArray#checkRequired #schema_array_SchemaArray-checkRequired
997
994
  * @see SchemaBoolean#checkRequired #schema_boolean_SchemaBoolean-checkRequired
998
- * @see SchemaBuffer#checkRequired #schema_buffer_SchemaBuffer.schemaName
995
+ * @see SchemaBuffer#checkRequired #schema_buffer_SchemaBuffer-schemaName
999
996
  * @see SchemaNumber#checkRequired #schema_number_SchemaNumber-min
1000
997
  * @see SchemaObjectId#checkRequired #schema_objectid_ObjectId-auto
1001
998
  * @see SchemaString#checkRequired #schema_string_SchemaString-checkRequired
@@ -1079,6 +1076,7 @@ SchemaType.prototype.required = function(required, message) {
1079
1076
  * looks at to determine the foreign collection it should query.
1080
1077
  *
1081
1078
  * #### Example:
1079
+ *
1082
1080
  * const userSchema = new Schema({ name: String });
1083
1081
  * const User = mongoose.model('User', userSchema);
1084
1082
  *
@@ -1108,6 +1106,7 @@ SchemaType.prototype.ref = function(ref) {
1108
1106
  *
1109
1107
  * @param {Object} scope the scope which callback are executed
1110
1108
  * @param {Boolean} init
1109
+ * @return {Any} The Stored default value.
1111
1110
  * @api private
1112
1111
  */
1113
1112
 
@@ -1175,6 +1174,7 @@ SchemaType.prototype._castNullish = function _castNullish(v) {
1175
1174
  * @param {Object} value
1176
1175
  * @param {Object} scope
1177
1176
  * @param {Boolean} init
1177
+ * @return {Any}
1178
1178
  * @api private
1179
1179
  */
1180
1180
 
@@ -1195,6 +1195,7 @@ SchemaType.prototype.applySetters = function(value, scope, init, priorVal, optio
1195
1195
  *
1196
1196
  * @param {Object} value
1197
1197
  * @param {Object} scope
1198
+ * @return {Any}
1198
1199
  * @api private
1199
1200
  */
1200
1201
 
@@ -1239,9 +1240,12 @@ SchemaType.prototype.select = function select(val) {
1239
1240
  /**
1240
1241
  * Performs a validation of `value` using the validators declared for this SchemaType.
1241
1242
  *
1242
- * @param {any} value
1243
+ * @param {Any} value
1243
1244
  * @param {Function} callback
1244
1245
  * @param {Object} scope
1246
+ * @param {Object} [options]
1247
+ * @param {String} [options.path]
1248
+ * @return {Any} If no validators, returns the output from calling `fn`, otherwise no return
1245
1249
  * @api public
1246
1250
  */
1247
1251
 
@@ -1352,9 +1356,11 @@ function _validate(ok, validatorProperties) {
1352
1356
  *
1353
1357
  * This method ignores the asynchronous validators.
1354
1358
  *
1355
- * @param {any} value
1359
+ * @param {Any} value
1356
1360
  * @param {Object} scope
1357
- * @return {MongooseError|undefined}
1361
+ * @param {Object} [options]
1362
+ * @param {Object} [options.path]
1363
+ * @return {MongooseError|null}
1358
1364
  * @api private
1359
1365
  */
1360
1366
 
@@ -1595,7 +1601,8 @@ SchemaType.prototype.castForQueryWrapper = function(params) {
1595
1601
  * Cast the given value with the given optional query operator.
1596
1602
  *
1597
1603
  * @param {String} [$conditional] query operator, like `$eq` or `$in`
1598
- * @param {any} val
1604
+ * @param {Any} val
1605
+ * @return {Any}
1599
1606
  * @api private
1600
1607
  */
1601
1608
 
@@ -1612,9 +1619,11 @@ SchemaType.prototype.castForQuery = function($conditional, val) {
1612
1619
  return this._castForQuery(val);
1613
1620
  };
1614
1621
 
1615
- /*!
1622
+ /**
1616
1623
  * Internal switch for runSetters
1617
1624
  *
1625
+ * @param {Any} val
1626
+ * @return {Any}
1618
1627
  * @api private
1619
1628
  */
1620
1629
 
@@ -1623,6 +1632,7 @@ SchemaType.prototype._castForQuery = function(val) {
1623
1632
  };
1624
1633
 
1625
1634
  /**
1635
+ * Set & Get the `checkRequired` function
1626
1636
  * Override the function the required validator uses to check whether a value
1627
1637
  * passes the `required` check. Override this on the individual SchemaType.
1628
1638
  *
@@ -1631,8 +1641,8 @@ SchemaType.prototype._castForQuery = function(val) {
1631
1641
  * // Use this to allow empty strings to pass the `required` validator
1632
1642
  * mongoose.Schema.Types.String.checkRequired(v => typeof v === 'string');
1633
1643
  *
1634
- * @param {Function} fn
1635
- * @return {Function}
1644
+ * @param {Function} [fn] If set, will overwrite the current set function
1645
+ * @return {Function} The input `fn` or the already set function
1636
1646
  * @static
1637
1647
  * @memberOf SchemaType
1638
1648
  * @function checkRequired
@@ -1650,7 +1660,8 @@ SchemaType.checkRequired = function(fn) {
1650
1660
  /**
1651
1661
  * Default check for if this path satisfies the `required` validator.
1652
1662
  *
1653
- * @param {any} val
1663
+ * @param {Any} val
1664
+ * @return {Boolean} `true` when the value is not `null`, `false` otherwise
1654
1665
  * @api private
1655
1666
  */
1656
1667
 
@@ -1658,8 +1669,11 @@ SchemaType.prototype.checkRequired = function(val) {
1658
1669
  return val != null;
1659
1670
  };
1660
1671
 
1661
- /*!
1662
- * ignore
1672
+ /**
1673
+ * Clone the current SchemaType
1674
+ *
1675
+ * @return {SchemaType} The cloned SchemaType instance
1676
+ * @api private
1663
1677
  */
1664
1678
 
1665
1679
  SchemaType.prototype.clone = function() {
@@ -13,18 +13,18 @@ const utils = require('./utils');
13
13
  * fullname instanceof mongoose.VirtualType // true
14
14
  *
15
15
  * @param {Object} options
16
- * @param {string|function} [options.ref] if `ref` is not nullish, this becomes a [populated virtual](/docs/populate.html#populate-virtuals)
17
- * @param {string|function} [options.localField] the local field to populate on if this is a populated virtual.
18
- * @param {string|function} [options.foreignField] the foreign field to populate on if this is a populated virtual.
19
- * @param {boolean} [options.justOne=false] by default, a populated virtual is an array. If you set `justOne`, the populated virtual will be a single doc or `null`.
20
- * @param {boolean} [options.getters=false] if you set this to `true`, Mongoose will call any custom getters you defined on this virtual
21
- * @param {boolean} [options.count=false] if you set this to `true`, `populate()` will set this virtual to the number of populated documents, as opposed to the documents themselves, using [`Query#countDocuments()`](./api.html#query_Query-countDocuments)
16
+ * @param {String|Function} [options.ref] if `ref` is not nullish, this becomes a [populated virtual](/docs/populate.html#populate-virtuals)
17
+ * @param {String|Function} [options.localField] the local field to populate on if this is a populated virtual.
18
+ * @param {String|Function} [options.foreignField] the foreign field to populate on if this is a populated virtual.
19
+ * @param {Boolean} [options.justOne=false] by default, a populated virtual is an array. If you set `justOne`, the populated virtual will be a single doc or `null`.
20
+ * @param {Boolean} [options.getters=false] if you set this to `true`, Mongoose will call any custom getters you defined on this virtual
21
+ * @param {Boolean} [options.count=false] if you set this to `true`, `populate()` will set this virtual to the number of populated documents, as opposed to the documents themselves, using [`Query#countDocuments()`](./api.html#query_Query-countDocuments)
22
22
  * @param {Object|Function} [options.match=null] add an extra match condition to `populate()`
23
23
  * @param {Number} [options.limit=null] add a default `limit` to the `populate()` query
24
24
  * @param {Number} [options.skip=null] add a default `skip` to the `populate()` query
25
25
  * @param {Number} [options.perDocumentLimit=null] For legacy reasons, `limit` with `populate()` may give incorrect results because it only executes a single query for every document being populated. If you set `perDocumentLimit`, Mongoose will ensure correct `limit` per document by executing a separate query for each document to `populate()`. For example, `.find().populate({ path: 'test', perDocumentLimit: 2 })` will execute 2 additional queries if `.find()` returns 2 documents.
26
26
  * @param {Object} [options.options=null] Additional options like `limit` and `lean`.
27
- * @param {string} name
27
+ * @param {String} name
28
28
  * @api public
29
29
  */
30
30
 
@@ -36,10 +36,8 @@ function VirtualType(options, name) {
36
36
  }
37
37
 
38
38
  /**
39
- * If no getters/getters, add a default
39
+ * If no getters/setters, add a default
40
40
  *
41
- * @param {Function} fn
42
- * @return {VirtualType} this
43
41
  * @api private
44
42
  */
45
43
 
@@ -51,10 +49,10 @@ VirtualType.prototype._applyDefaultGetters = function() {
51
49
  const path = this.path;
52
50
  const internalProperty = '$' + path;
53
51
  this.getters.push(function() {
54
- return this[internalProperty];
52
+ return this.$locals[internalProperty];
55
53
  });
56
54
  this.setters.push(function(v) {
57
- this[internalProperty] = v;
55
+ this.$locals[internalProperty] = v;
58
56
  });
59
57
  };
60
58
 
@@ -85,7 +83,7 @@ VirtualType.prototype.clone = function() {
85
83
  * return this.name.first + ' ' + this.name.last;
86
84
  * });
87
85
  *
88
- * @param {function} fn
86
+ * @param {Function} fn
89
87
  * @return {VirtualType} this
90
88
  * @api public
91
89
  */
@@ -120,7 +118,7 @@ VirtualType.prototype.get = function(fn) {
120
118
  * doc.name.first; // 'Jean-Luc'
121
119
  * doc.name.last; // 'Picard'
122
120
  *
123
- * @param {function} fn
121
+ * @param {Function} fn
124
122
  * @return {VirtualType} this
125
123
  * @api public
126
124
  */
@@ -135,7 +133,7 @@ VirtualType.prototype.set = function(fn) {
135
133
  *
136
134
  * @param {Object} value
137
135
  * @param {Document} doc The document this virtual is attached to
138
- * @return {any} the value after applying all getters
136
+ * @return {Any} the value after applying all getters
139
137
  * @api public
140
138
  */
141
139
 
@@ -158,7 +156,7 @@ VirtualType.prototype.applyGetters = function(value, doc) {
158
156
  *
159
157
  * @param {Object} value
160
158
  * @param {Document} doc
161
- * @return {any} the value after applying all setters
159
+ * @return {Any} the value after applying all setters
162
160
  * @api public
163
161
  */
164
162
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.4.4",
4
+ "version": "6.4.7",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -60,7 +60,7 @@
60
60
  "serve-handler": "6.1.3",
61
61
  "sinon": "14.0.0",
62
62
  "stream-browserify": "3.0.0",
63
- "ts-benchmark": "^1.0.2",
63
+ "ts-benchmark": "^1.1.10",
64
64
  "tsd": "0.20.0",
65
65
  "typescript": "4.7.4",
66
66
  "uuid": "8.3.2",
@@ -98,8 +98,8 @@
98
98
  "test-tsd": "node ./test/types/check-types-filename && tsd",
99
99
  "tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
100
100
  "test-coverage": "nyc --reporter=html --reporter=text npm test",
101
- "ts-benchmark": "node ./benchmarks/typescript.js",
102
- "ts-benchmark-watch": "ts-benchmark -p ./benchmarks/typescript/simple -w ./types -i -s -f 17 18 29 32 -b master"
101
+ "ts-benchmark": "ts-benchmark -p ./benchmarks/typescript/simple -f 17/100000 18 29 32",
102
+ "ts-benchmark-watch": "ts-benchmark -p ./benchmarks/typescript/simple -w ./types -i -s -f 17/100000 18 29 32 -b master"
103
103
  },
104
104
  "main": "./index.js",
105
105
  "types": "./types/index.d.ts",
@@ -229,7 +229,7 @@ declare module 'mongoose' {
229
229
  /** The username specified in the URI */
230
230
  readonly user: string;
231
231
 
232
- /** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model.watch). */
232
+ /** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model-watch). */
233
233
  watch<ResultType extends mongodb.Document = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
234
234
  }
235
235