mongoose 6.4.3 → 6.4.4

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 (45) hide show
  1. package/lib/aggregate.js +3 -2
  2. package/lib/connection.js +9 -9
  3. package/lib/cursor/AggregationCursor.js +3 -2
  4. package/lib/cursor/QueryCursor.js +5 -4
  5. package/lib/document.js +43 -15
  6. package/lib/error/index.js +12 -12
  7. package/lib/error/messages.js +2 -2
  8. package/lib/helpers/query/castUpdate.js +4 -4
  9. package/lib/index.js +5 -2
  10. package/lib/model.js +22 -21
  11. package/lib/options/SchemaArrayOptions.js +2 -2
  12. package/lib/options/SchemaBufferOptions.js +1 -1
  13. package/lib/options/SchemaDateOptions.js +3 -3
  14. package/lib/options/SchemaDocumentArrayOptions.js +2 -2
  15. package/lib/options/SchemaMapOptions.js +1 -1
  16. package/lib/options/SchemaNumberOptions.js +4 -4
  17. package/lib/options/SchemaObjectIdOptions.js +2 -2
  18. package/lib/options/SchemaStringOptions.js +8 -8
  19. package/lib/options/SchemaSubdocumentOptions.js +1 -1
  20. package/lib/options/SchemaTypeOptions.js +14 -14
  21. package/lib/options/VirtualOptions.js +11 -11
  22. package/lib/query.js +74 -71
  23. package/lib/schema/SubdocumentPath.js +10 -6
  24. package/lib/schema/array.js +3 -3
  25. package/lib/schema/boolean.js +5 -5
  26. package/lib/schema/buffer.js +2 -2
  27. package/lib/schema/date.js +2 -2
  28. package/lib/schema/decimal128.js +2 -2
  29. package/lib/schema/documentarray.js +12 -8
  30. package/lib/schema/mixed.js +2 -2
  31. package/lib/schema/number.js +2 -2
  32. package/lib/schema/objectid.js +2 -2
  33. package/lib/schema/string.js +2 -2
  34. package/lib/schema.js +69 -34
  35. package/lib/schematype.js +7 -9
  36. package/lib/types/DocumentArray/methods/index.js +1 -1
  37. package/lib/types/buffer.js +8 -4
  38. package/lib/types/decimal128.js +1 -1
  39. package/lib/types/map.js +1 -1
  40. package/lib/types/objectid.js +1 -1
  41. package/lib/types/subdocument.js +1 -1
  42. package/lib/virtualtype.js +5 -5
  43. package/package.json +5 -5
  44. package/types/models.d.ts +2 -1
  45. package/types/query.d.ts +6 -1
@@ -56,8 +56,8 @@ Decimal128._cast = castDecimal128;
56
56
  * const User = mongoose.model('User', new Schema({ test: mongoose.Decimal128 }));
57
57
  * new User({ }).validateSync().errors.test.message; // Path `test` is required.
58
58
  *
59
- * @param {String} option - The option you'd like to set the value for
60
- * @param {*} value - value for option
59
+ * @param {String} option The option you'd like to set the value for
60
+ * @param {Any} value value for option
61
61
  * @return {undefined}
62
62
  * @function set
63
63
  * @static
@@ -536,9 +536,9 @@ DocumentArrayPath.prototype.applyGetters = function(value, scope) {
536
536
  * Scopes paths selected in a query to this array.
537
537
  * Necessary for proper default application of subdocument values.
538
538
  *
539
- * @param {DocumentArrayPath} array - the array to scope `fields` paths
540
- * @param {Object|undefined} fields - the root fields selected in the query
541
- * @param {Boolean|undefined} init - if we are being created part of a query result
539
+ * @param {DocumentArrayPath} array the array to scope `fields` paths
540
+ * @param {Object|undefined} fields the root fields selected in the query
541
+ * @param {Boolean|undefined} init if we are being created part of a query result
542
542
  */
543
543
 
544
544
  function scopePaths(array, fields, init) {
@@ -572,6 +572,12 @@ function scopePaths(array, fields, init) {
572
572
  return hasKeys && selected || undefined;
573
573
  }
574
574
 
575
+ /*!
576
+ * ignore
577
+ */
578
+
579
+ DocumentArrayPath.defaultOptions = {};
580
+
575
581
  /**
576
582
  * Sets a default option for all DocumentArray instances.
577
583
  *
@@ -580,16 +586,14 @@ function scopePaths(array, fields, init) {
580
586
  * // Make all numbers have option `min` equal to 0.
581
587
  * mongoose.Schema.DocumentArray.set('_id', false);
582
588
  *
583
- * @param {String} option - The option you'd like to set the value for
584
- * @param {*} value - value for option
585
- * @return {undefined}
589
+ * @param {String} option The name of the option you'd like to set (e.g. trim, lowercase, etc...)
590
+ * @param {Any} value The value of the option you'd like to set.
591
+ * @return {void}
586
592
  * @function set
587
593
  * @static
588
594
  * @api public
589
595
  */
590
596
 
591
- DocumentArrayPath.defaultOptions = {};
592
-
593
597
  DocumentArrayPath.set = SchemaType.set;
594
598
 
595
599
  /*!
@@ -84,8 +84,8 @@ Mixed.get = SchemaType.get;
84
84
  * const User = mongoose.model('User', new Schema({ test: mongoose.Mixed }));
85
85
  * new User({ }).validateSync().errors.test.message; // Path `test` is required.
86
86
  *
87
- * @param {String} option - The option you'd like to set the value for
88
- * @param {*} value - value for option
87
+ * @param {String} option The option you'd like to set the value for
88
+ * @param {Any} value value for option
89
89
  * @return {undefined}
90
90
  * @function set
91
91
  * @static
@@ -57,8 +57,8 @@ SchemaNumber.get = SchemaType.get;
57
57
  * const Order = mongoose.model('Order', new Schema({ amount: Number }));
58
58
  * new Order({ amount: -10 }).validateSync().errors.amount.message; // Path `amount` must be larger than 0.
59
59
  *
60
- * @param {String} option - The option you'd like to set the value for
61
- * @param {*} value - value for option
60
+ * @param {String} option The option you'd like to set the value for
61
+ * @param {Any} value value for option
62
62
  * @return {undefined}
63
63
  * @function set
64
64
  * @static
@@ -84,8 +84,8 @@ ObjectId.get = SchemaType.get;
84
84
  * const Order = mongoose.model('Order', new Schema({ userId: ObjectId }));
85
85
  * new Order({ }).validateSync().errors.userId.message; // Path `userId` is required.
86
86
  *
87
- * @param {String} option - The option you'd like to set the value for
88
- * @param {*} value - value for option
87
+ * @param {String} option The option you'd like to set the value for
88
+ * @param {Any} value value for option
89
89
  * @return {undefined}
90
90
  * @function set
91
91
  * @static
@@ -133,8 +133,8 @@ SchemaString.get = SchemaType.get;
133
133
  * const User = mongoose.model('User', new Schema({ name: String }));
134
134
  * new User({ name: ' John Doe ' }).name; // 'John Doe'
135
135
  *
136
- * @param {String} option - The option you'd like to set the value for
137
- * @param {*} value - value for option
136
+ * @param {String} option The option you'd like to set the value for
137
+ * @param {Any} value value for option
138
138
  * @return {undefined}
139
139
  * @function set
140
140
  * @static
package/lib/schema.js CHANGED
@@ -79,6 +79,7 @@ let id = 0;
79
79
  * - [pluginTags](/docs/guide.html#pluginTags): array of strings - defaults to `undefined`. If set and plugin called with `tags` option, will only apply that plugin to schemas with a matching tag.
80
80
  *
81
81
  * #### Options for Nested Schemas:
82
+ *
82
83
  * - `excludeIndexes`: bool - defaults to `false`. If `true`, skip building indexes on this schema's paths.
83
84
  *
84
85
  * #### Note:
@@ -233,6 +234,7 @@ Object.defineProperty(Schema.prototype, 'childSchemas', {
233
234
  * You do not need to interact with this property at all to use mongoose.
234
235
  *
235
236
  * #### Example:
237
+ *
236
238
  * const schema = new Schema({});
237
239
  * schema.virtual('answer').get(() => 42);
238
240
  *
@@ -272,6 +274,7 @@ Schema.prototype.obj;
272
274
  * in this schema, and the values are instances of the SchemaType class.
273
275
  *
274
276
  * #### Example:
277
+ *
275
278
  * const schema = new Schema({ name: String }, { _id: false });
276
279
  * schema.paths; // { name: SchemaString { ... } }
277
280
  *
@@ -290,6 +293,7 @@ Schema.prototype.paths;
290
293
  * Schema as a tree
291
294
  *
292
295
  * #### Example:
296
+ *
293
297
  * {
294
298
  * '_id' : ObjectId
295
299
  * , 'nested' : {
@@ -395,8 +399,8 @@ Schema.prototype._clone = function _clone(Constructor) {
395
399
  * newSchema.path('name'); // SchemaString { ... }
396
400
  * newSchema.path('age'); // undefined
397
401
  *
398
- * @param {Array} paths list of paths to pick
399
- * @param {Object} [options] options to pass to the schema constructor. Defaults to `this.options` if not set.
402
+ * @param {String[]} paths List of Paths to pick for the new Schema
403
+ * @param {Object} [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`). Defaults to `this.options` if not set.
400
404
  * @return {Schema}
401
405
  * @api public
402
406
  */
@@ -426,8 +430,8 @@ Schema.prototype.pick = function(paths, options) {
426
430
  /**
427
431
  * Returns default options for this schema, merged with `options`.
428
432
  *
429
- * @param {Object} options
430
- * @return {Object}
433
+ * @param {Object} [options] Options to overwrite the default options
434
+ * @return {Object} The merged options of `options` and the default options
431
435
  * @api private
432
436
  */
433
437
 
@@ -755,6 +759,10 @@ Schema.prototype.clearIndexes = function clearIndexes() {
755
759
  *
756
760
  * const schema = new Schema(..);
757
761
  * schema.methods.init = function () {} // potentially breaking
762
+ *
763
+ * @property reserved
764
+ * @memberOf Schema
765
+ * @static
758
766
  */
759
767
 
760
768
  Schema.reserved = Object.create(null);
@@ -788,13 +796,13 @@ reserved.collection = 1;
788
796
  * Sets a path (if arity 2)
789
797
  * Gets a path (if arity 1)
790
798
  *
791
- * #### Example
799
+ * #### Example:
792
800
  *
793
801
  * schema.path('name') // returns a SchemaType
794
802
  * schema.path('name', Number) // changes the schemaType of `name` to Number
795
803
  *
796
- * @param {String} path
797
- * @param {Object} constructor
804
+ * @param {String} path The name of the Path to get / set
805
+ * @param {Object} [obj] The Type to set the path to, if provided the path will be SET, otherwise the path will be GET
798
806
  * @api public
799
807
  */
800
808
 
@@ -1059,6 +1067,7 @@ Object.defineProperty(Schema.prototype, 'base', {
1059
1067
  *
1060
1068
  * @param {String} path
1061
1069
  * @param {Object} obj constructor
1070
+ * @param {Object} options
1062
1071
  * @api private
1063
1072
  */
1064
1073
 
@@ -1316,6 +1325,7 @@ Schema.prototype.eachPath = function(fn) {
1316
1325
  * Returns an Array of path strings that are required by this schema.
1317
1326
  *
1318
1327
  * #### Example:
1328
+ *
1319
1329
  * const s = new Schema({
1320
1330
  * name: { type: String, required: true },
1321
1331
  * age: { type: String, required: true },
@@ -1324,7 +1334,7 @@ Schema.prototype.eachPath = function(fn) {
1324
1334
  * s.requiredPaths(); // [ 'age', 'name' ]
1325
1335
  *
1326
1336
  * @api public
1327
- * @param {Boolean} invalidate refresh the cache
1337
+ * @param {Boolean} invalidate Refresh the cache
1328
1338
  * @return {Array}
1329
1339
  */
1330
1340
 
@@ -1545,7 +1555,7 @@ Schema.prototype.queue = function(name, args) {
1545
1555
  /**
1546
1556
  * Defines a pre hook for the model.
1547
1557
  *
1548
- * #### Example
1558
+ * #### Example:
1549
1559
  *
1550
1560
  * const toySchema = new Schema({ name: String, created: Date });
1551
1561
  *
@@ -1577,7 +1587,7 @@ Schema.prototype.queue = function(name, args) {
1577
1587
  * // Runs when you call `doc.deleteOne()`
1578
1588
  * });
1579
1589
  *
1580
- * @param {String|RegExp} The method name or regular expression to match method name
1590
+ * @param {String|RegExp|String[]} methodName The method name or regular expression to match method name
1581
1591
  * @param {Object} [options]
1582
1592
  * @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware. For example, set `options.document` to `true` to apply this hook to `Document#deleteOne()` rather than `Query#deleteOne()`.
1583
1593
  * @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
@@ -1633,7 +1643,7 @@ Schema.prototype.pre = function(name) {
1633
1643
  * console.log('this fires after the post find hook');
1634
1644
  * });
1635
1645
  *
1636
- * @param {String|RegExp} The method name or regular expression to match method name
1646
+ * @param {String|RegExp|String[]} methodName The method name or regular expression to match method name
1637
1647
  * @param {Object} [options]
1638
1648
  * @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware.
1639
1649
  * @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
@@ -1673,8 +1683,14 @@ Schema.prototype.post = function(name) {
1673
1683
  * s.plugin(schema => console.log(schema.path('name').path));
1674
1684
  * mongoose.model('Test', s); // Prints 'name'
1675
1685
  *
1676
- * @param {Function} plugin callback
1677
- * @param {Object} [opts]
1686
+ * Or with Options:
1687
+ *
1688
+ * const s = new Schema({ name: String });
1689
+ * s.plugin((schema, opts) => console.log(opts.text, schema.path('name').path), { text: "Schema Path Name:" });
1690
+ * mongoose.model('Test', s); // Prints 'Schema Path Name: name'
1691
+ *
1692
+ * @param {Function} plugin The Plugin's callback
1693
+ * @param {Object} [opts] Options to pass to the plugin
1678
1694
  * @see plugins
1679
1695
  * @api public
1680
1696
  */
@@ -1701,7 +1717,7 @@ Schema.prototype.plugin = function(fn, opts) {
1701
1717
  /**
1702
1718
  * Adds an instance method to documents constructed from Models compiled from this schema.
1703
1719
  *
1704
- * #### Example
1720
+ * #### Example:
1705
1721
  *
1706
1722
  * const schema = kittySchema = new Schema(..);
1707
1723
  *
@@ -1722,13 +1738,14 @@ Schema.prototype.plugin = function(fn, opts) {
1722
1738
  * });
1723
1739
  *
1724
1740
  * // later
1741
+ * const fizz = new Kitty;
1725
1742
  * fizz.purr();
1726
1743
  * fizz.scratch();
1727
1744
  *
1728
1745
  * NOTE: `Schema.method()` adds instance methods to the `Schema.methods` object. You can also add instance methods directly to the `Schema.methods` object as seen in the [guide](/docs/guide.html#methods)
1729
1746
  *
1730
- * @param {String|Object} method name
1731
- * @param {Function} [fn]
1747
+ * @param {String|Object} name The Method Name for a single function, or a Object of "string-function" pairs.
1748
+ * @param {Function} [fn] The Function in a single-function definition.
1732
1749
  * @api public
1733
1750
  */
1734
1751
 
@@ -1748,7 +1765,7 @@ Schema.prototype.method = function(name, fn, options) {
1748
1765
  /**
1749
1766
  * Adds static "class" methods to Models compiled from this schema.
1750
1767
  *
1751
- * #### Example
1768
+ * #### Example:
1752
1769
  *
1753
1770
  * const schema = new Schema(..);
1754
1771
  * // Equivalent to `schema.statics.findByName = function(name) {}`;
@@ -1759,10 +1776,21 @@ Schema.prototype.method = function(name, fn, options) {
1759
1776
  * const Drink = mongoose.model('Drink', schema);
1760
1777
  * await Drink.findByName('LaCroix');
1761
1778
  *
1779
+ * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as methods.
1780
+ *
1781
+ * schema.static({
1782
+ * findByName: function () {..}
1783
+ * , findByCost: function () {..}
1784
+ * });
1785
+ *
1786
+ * const Drink = mongoose.model('Drink', schema);
1787
+ * await Drink.findByName('LaCroix');
1788
+ * await Drink.findByCost(3);
1789
+ *
1762
1790
  * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as statics.
1763
1791
  *
1764
- * @param {String|Object} name
1765
- * @param {Function} [fn]
1792
+ * @param {String|Object} name The Method Name for a single function, or a Object of "string-function" pairs.
1793
+ * @param {Function} [fn] The Function in a single-function definition.
1766
1794
  * @api public
1767
1795
  * @see Statics /docs/guide.html#statics
1768
1796
  */
@@ -1781,11 +1809,11 @@ Schema.prototype.static = function(name, fn) {
1781
1809
  /**
1782
1810
  * Defines an index (most likely compound) for this schema.
1783
1811
  *
1784
- * #### Example
1812
+ * #### Example:
1785
1813
  *
1786
1814
  * schema.index({ first: 1, last: -1 })
1787
1815
  *
1788
- * @param {Object} fields
1816
+ * @param {Object} fields The Fields to index, with the order, available values: `1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text'`
1789
1817
  * @param {Object} [options] Options to pass to [MongoDB driver's `createIndex()` function](https://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#createIndex)
1790
1818
  * @param {String | number} [options.expires=null] Mongoose-specific syntactic sugar, uses [ms](https://www.npmjs.com/package/ms) to convert `expires` option into seconds for the `expireAfterSeconds` in the above link.
1791
1819
  * @api public
@@ -1806,14 +1834,14 @@ Schema.prototype.index = function(fields, options) {
1806
1834
  /**
1807
1835
  * Sets a schema option.
1808
1836
  *
1809
- * #### Example
1837
+ * #### Example:
1810
1838
  *
1811
1839
  * schema.set('strict'); // 'true' by default
1812
1840
  * schema.set('strict', false); // Sets 'strict' to false
1813
1841
  * schema.set('strict'); // 'false'
1814
1842
  *
1815
- * @param {String} key option name
1816
- * @param {Object} [value] if not passed, the current option value is returned
1843
+ * @param {String} key The name of the option to set the value to
1844
+ * @param {Object} [value] The value to set the option to, if not passed, the option will be reset to default
1817
1845
  * @see Schema ./
1818
1846
  * @api public
1819
1847
  */
@@ -1861,7 +1889,7 @@ Schema.prototype.set = function(key, value, _tags) {
1861
1889
  * schema.set('strict', false);
1862
1890
  * schema.get('strict'); // false
1863
1891
  *
1864
- * @param {String} key option name
1892
+ * @param {String} key The name of the Option to get the current value for
1865
1893
  * @api public
1866
1894
  * @return {Any} the option's value
1867
1895
  */
@@ -1870,16 +1898,17 @@ Schema.prototype.get = function(key) {
1870
1898
  return this.options[key];
1871
1899
  };
1872
1900
 
1901
+ const indexTypes = '2d 2dsphere hashed text'.split(' ');
1902
+
1873
1903
  /**
1874
1904
  * The allowed index types
1875
1905
  *
1876
- * @receiver Schema
1877
- * @static indexTypes
1906
+ * @property {String[]} indexTypes
1907
+ * @memberOf Schema
1908
+ * @static
1878
1909
  * @api public
1879
1910
  */
1880
1911
 
1881
- const indexTypes = '2d 2dsphere hashed text'.split(' ');
1882
-
1883
1912
  Object.defineProperty(Schema, 'indexTypes', {
1884
1913
  get: function() {
1885
1914
  return indexTypes;
@@ -1926,7 +1955,7 @@ Schema.prototype.indexes = function() {
1926
1955
  /**
1927
1956
  * Creates a virtual type with the given name.
1928
1957
  *
1929
- * @param {String} name
1958
+ * @param {String} name The name of the Virtual
1930
1959
  * @param {Object} [options]
1931
1960
  * @param {String|Model} [options.ref] model name or model instance. Marks this as a [populate virtual](/docs/populate.html#populate-virtuals).
1932
1961
  * @param {String|Function} [options.localField] Required for populate virtuals. See [populate virtual docs](/docs/populate.html#populate-virtuals) for more information.
@@ -2044,8 +2073,8 @@ Schema.prototype.virtual = function(name, options) {
2044
2073
  /**
2045
2074
  * Returns the virtual type with the given `name`.
2046
2075
  *
2047
- * @param {String} name
2048
- * @return {VirtualType}
2076
+ * @param {String} name The name of the Virtual to get
2077
+ * @return {VirtualType|null}
2049
2078
  */
2050
2079
 
2051
2080
  Schema.prototype.virtualpath = function(name) {
@@ -2062,7 +2091,13 @@ Schema.prototype.virtualpath = function(name) {
2062
2091
  * schema.path('name'); // Undefined
2063
2092
  * schema.path('age'); // SchemaNumber { ... }
2064
2093
  *
2065
- * @param {String|Array} path
2094
+ * Or as a Array:
2095
+ *
2096
+ * schema.remove(['name', 'age']);
2097
+ * schema.path('name'); // Undefined
2098
+ * schema.path('age'); // Undefined
2099
+ *
2100
+ * @param {String|Array} path The Path(s) to remove
2066
2101
  * @return {Schema} the Schema instance
2067
2102
  * @api public
2068
2103
  */
@@ -2150,7 +2185,7 @@ function _deletePath(schema, name) {
2150
2185
  * userSchema.loadClass(UserClass);
2151
2186
  * ```
2152
2187
  *
2153
- * @param {Function} model
2188
+ * @param {Function} model The Class to load
2154
2189
  * @param {Boolean} [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
2155
2190
  */
2156
2191
  Schema.prototype.loadClass = function(model, virtualsOnly) {
package/lib/schematype.js CHANGED
@@ -206,7 +206,7 @@ SchemaType.prototype.splitPath = function() {
206
206
  * @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed
207
207
  * @return {Function}
208
208
  * @static
209
- * @receiver SchemaType
209
+ * @memberOf SchemaType
210
210
  * @function cast
211
211
  * @api public
212
212
  */
@@ -239,9 +239,7 @@ SchemaType.cast = function cast(caster) {
239
239
  *
240
240
  * @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed
241
241
  * @return {Function}
242
- * @static
243
- * @receiver SchemaType
244
- * @function cast
242
+ * @memberOf SchemaType
245
243
  * @api public
246
244
  */
247
245
 
@@ -279,10 +277,10 @@ SchemaType.prototype.cast = function cast() {
279
277
  * mongoose.SchemaTypes.String.set('trim', true);
280
278
  *
281
279
  * @param {String} option The name of the option you'd like to set (e.g. trim, lowercase, etc...)
282
- * @param {*} value The value of the option you'd like to set.
280
+ * @param {Any} value The value of the option you'd like to set.
283
281
  * @return {void}
284
282
  * @static
285
- * @receiver SchemaType
283
+ * @memberOf SchemaType
286
284
  * @function set
287
285
  * @api public
288
286
  */
@@ -305,7 +303,7 @@ SchemaType.set = function set(option, value) {
305
303
  * @param {Function} getter
306
304
  * @return {this}
307
305
  * @static
308
- * @receiver SchemaType
306
+ * @memberOf SchemaType
309
307
  * @function get
310
308
  * @api public
311
309
  */
@@ -1244,7 +1242,7 @@ SchemaType.prototype.select = function select(val) {
1244
1242
  * @param {any} value
1245
1243
  * @param {Function} callback
1246
1244
  * @param {Object} scope
1247
- * @api private
1245
+ * @api public
1248
1246
  */
1249
1247
 
1250
1248
  SchemaType.prototype.doValidate = function(value, fn, scope, options) {
@@ -1636,7 +1634,7 @@ SchemaType.prototype._castForQuery = function(val) {
1636
1634
  * @param {Function} fn
1637
1635
  * @return {Function}
1638
1636
  * @static
1639
- * @receiver SchemaType
1637
+ * @memberOf SchemaType
1640
1638
  * @function checkRequired
1641
1639
  * @api public
1642
1640
  */
@@ -35,7 +35,7 @@ const methods = {
35
35
  *
36
36
  * @method _cast
37
37
  * @api private
38
- * @receiver MongooseDocumentArray
38
+ * @memberOf MongooseDocumentArray
39
39
  */
40
40
 
41
41
  _cast(value, index) {
@@ -70,7 +70,8 @@ MongooseBuffer.mixin = {
70
70
  *
71
71
  * @api private
72
72
  * @property _subtype
73
- * @memberOf MongooseBuffer
73
+ * @memberOf MongooseBuffer.mixin
74
+ * @static
74
75
  */
75
76
 
76
77
  _subtype: undefined,
@@ -80,7 +81,8 @@ MongooseBuffer.mixin = {
80
81
  *
81
82
  * @api private
82
83
  * @method _markModified
83
- * @memberOf MongooseBuffer
84
+ * @memberOf MongooseBuffer.mixin
85
+ * @static
84
86
  */
85
87
 
86
88
  _markModified: function() {
@@ -97,7 +99,8 @@ MongooseBuffer.mixin = {
97
99
  *
98
100
  * @api public
99
101
  * @method write
100
- * @memberOf MongooseBuffer
102
+ * @memberOf MongooseBuffer.mixin
103
+ * @static
101
104
  */
102
105
 
103
106
  write: function() {
@@ -120,7 +123,8 @@ MongooseBuffer.mixin = {
120
123
  * @return {Number} The number of bytes copied.
121
124
  * @param {Buffer} target
122
125
  * @method copy
123
- * @memberOf MongooseBuffer
126
+ * @memberOf MongooseBuffer.mixin
127
+ * @static
124
128
  */
125
129
 
126
130
  copy: function(target) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Decimal128 type constructor
3
3
  *
4
- * #### Example
4
+ * #### Example:
5
5
  *
6
6
  * const id = new mongoose.Types.Decimal128('3.1415');
7
7
  *
package/lib/types/map.js CHANGED
@@ -275,7 +275,7 @@ Object.defineProperty(MongooseMap.prototype, '$__schemaType', {
275
275
  *
276
276
  * @api public
277
277
  * @property $isMongooseMap
278
- * @memberOf Map
278
+ * @memberOf MongooseMap
279
279
  * @instance
280
280
  */
281
281
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ObjectId type constructor
3
3
  *
4
- * #### Example
4
+ * #### Example:
5
5
  *
6
6
  * const id = new mongoose.Types.ObjectId;
7
7
  *
@@ -188,7 +188,7 @@ Subdocument.prototype.isModified = function(paths, modifiedPaths) {
188
188
  * @param {String} path the field to mark as valid
189
189
  * @api private
190
190
  * @method $markValid
191
- * @receiver Subdocument
191
+ * @memberOf Subdocument
192
192
  */
193
193
 
194
194
  Subdocument.prototype.$markValid = function(path) {
@@ -75,7 +75,7 @@ VirtualType.prototype.clone = function() {
75
75
  * Mongoose calls the getter function with the below 3 parameters.
76
76
  *
77
77
  * - `value`: the value returned by the previous getter. If there is only one getter, `value` will be `undefined`.
78
- * - `virtual`: the virtual object you called `.get()` on
78
+ * - `virtual`: the virtual object you called `.get()` on.
79
79
  * - `doc`: the document this virtual is attached to. Equivalent to `this`.
80
80
  *
81
81
  * #### Example:
@@ -85,7 +85,7 @@ VirtualType.prototype.clone = function() {
85
85
  * return this.name.first + ' ' + this.name.last;
86
86
  * });
87
87
  *
88
- * @param {Function(Any, VirtualType, Document)} fn
88
+ * @param {function} fn
89
89
  * @return {VirtualType} this
90
90
  * @api public
91
91
  */
@@ -100,8 +100,8 @@ VirtualType.prototype.get = function(fn) {
100
100
  *
101
101
  * Mongoose calls the setter function with the below 3 parameters.
102
102
  *
103
- * - `value`: the value being set
104
- * - `virtual`: the virtual object you're calling `.set()` on
103
+ * - `value`: the value being set.
104
+ * - `virtual`: the virtual object you're calling `.set()` on.
105
105
  * - `doc`: the document this virtual is attached to. Equivalent to `this`.
106
106
  *
107
107
  * #### Example:
@@ -120,7 +120,7 @@ VirtualType.prototype.get = function(fn) {
120
120
  * doc.name.first; // 'Jean-Luc'
121
121
  * doc.name.last; // 'Picard'
122
122
  *
123
- * @param {Function(Any, VirtualType, Document)} fn
123
+ * @param {function} fn
124
124
  * @return {VirtualType} this
125
125
  * @api public
126
126
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.4.3",
4
+ "version": "6.4.4",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -42,7 +42,7 @@
42
42
  "buffer": "^5.6.0",
43
43
  "cheerio": "1.0.0-rc.12",
44
44
  "crypto-browserify": "3.12.0",
45
- "dox": "0.3.1",
45
+ "dox": "0.9.1",
46
46
  "eslint": "8.19.0",
47
47
  "eslint-plugin-mocha-no-only": "1.1.1",
48
48
  "highlight.js": "11.5.1",
@@ -61,7 +61,7 @@
61
61
  "sinon": "14.0.0",
62
62
  "stream-browserify": "3.0.0",
63
63
  "ts-benchmark": "^1.0.2",
64
- "tsd": "0.22.0",
64
+ "tsd": "0.20.0",
65
65
  "typescript": "4.7.4",
66
66
  "uuid": "8.3.2",
67
67
  "webpack": "5.73.0"
@@ -98,7 +98,7 @@
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": "ts-benchmark -p ./benchmarks/typescript/simple -f 17 18 29 32",
101
+ "ts-benchmark": "node ./benchmarks/typescript.js",
102
102
  "ts-benchmark-watch": "ts-benchmark -p ./benchmarks/typescript/simple -w ./types -i -s -f 17 18 29 32 -b master"
103
103
  },
104
104
  "main": "./index.js",
@@ -145,4 +145,4 @@
145
145
  "target": "ES2017"
146
146
  }
147
147
  }
148
- }
148
+ }
package/types/models.d.ts CHANGED
@@ -106,7 +106,7 @@ declare module 'mongoose' {
106
106
  checkKeys?: boolean;
107
107
  j?: boolean;
108
108
  safe?: boolean | WriteConcern;
109
- timestamps?: boolean;
109
+ timestamps?: boolean | QueryTimestampsConfig;
110
110
  validateBeforeSave?: boolean;
111
111
  validateModifiedOnly?: boolean;
112
112
  w?: number | string;
@@ -351,6 +351,7 @@ declare module 'mongoose' {
351
351
  findOneAndRemove<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
352
352
 
353
353
  /** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
354
+ findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions<T> & { rawResult: true }, callback?: (err: CallbackError, doc: any, res: any) => void): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, T>;
354
355
  findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter: FilterQuery<T>, replacement: T | AnyObject, options: QueryOptions<T> & { upsert: true } & ReturnsNewDoc, callback?: (err: CallbackError, doc: ResultDoc, res: any) => void): QueryWithHelpers<ResultDoc, ResultDoc, TQueryHelpers, T>;
355
356
  findOneAndReplace<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(filter?: FilterQuery<T>, replacement?: T | AnyObject, options?: QueryOptions<T> | null, callback?: (err: CallbackError, doc: ResultDoc | null, res: any) => void): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, T>;
356
357