mongoose 7.0.4 → 7.1.0

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 (43) hide show
  1. package/.eslintrc.js +4 -3
  2. package/README.md +1 -1
  3. package/dist/browser.umd.js +1 -1
  4. package/lib/aggregate.js +13 -13
  5. package/lib/browser.js +12 -12
  6. package/lib/cast/bigint.js +31 -0
  7. package/lib/connection.js +45 -8
  8. package/lib/cursor/AggregationCursor.js +1 -1
  9. package/lib/cursor/QueryCursor.js +1 -1
  10. package/lib/document.js +44 -44
  11. package/lib/error/createCollectionsError.js +26 -0
  12. package/lib/error/index.js +13 -13
  13. package/lib/index.js +40 -40
  14. package/lib/model.js +102 -95
  15. package/lib/options/SchemaNumberOptions.js +1 -1
  16. package/lib/options/SchemaObjectIdOptions.js +1 -1
  17. package/lib/options/SchemaStringOptions.js +1 -1
  18. package/lib/options/SchemaTypeOptions.js +1 -1
  19. package/lib/options/VirtualOptions.js +1 -1
  20. package/lib/query.js +87 -71
  21. package/lib/schema/SubdocumentPath.js +1 -1
  22. package/lib/schema/bigint.js +221 -0
  23. package/lib/schema/boolean.js +4 -0
  24. package/lib/schema/date.js +2 -2
  25. package/lib/schema/documentarray.js +1 -1
  26. package/lib/schema/index.js +8 -19
  27. package/lib/schema/number.js +3 -3
  28. package/lib/schema/string.js +7 -7
  29. package/lib/schema/uuid.js +10 -8
  30. package/lib/schema.js +49 -47
  31. package/lib/schematype.js +17 -16
  32. package/lib/types/array/methods/index.js +12 -12
  33. package/lib/types/index.js +2 -0
  34. package/lib/types/uuid.js +13 -0
  35. package/lib/utils.js +2 -0
  36. package/lib/virtualtype.js +2 -2
  37. package/package.json +3 -3
  38. package/scripts/generateSearch.js +2 -1
  39. package/scripts/tsc-diagnostics-check.js +1 -1
  40. package/types/index.d.ts +68 -28
  41. package/types/inferschematype.d.ts +2 -3
  42. package/types/middlewares.d.ts +10 -3
  43. package/types/query.d.ts +2 -1
package/lib/query.js CHANGED
@@ -26,6 +26,7 @@ const helpers = require('./queryhelpers');
26
26
  const immediate = require('./helpers/immediate');
27
27
  const isExclusive = require('./helpers/projection/isExclusive');
28
28
  const isInclusive = require('./helpers/projection/isInclusive');
29
+ const isPathSelectedInclusive = require('./helpers/projection/isPathSelectedInclusive');
29
30
  const isSubpath = require('./helpers/projection/isSubpath');
30
31
  const mpath = require('mpath');
31
32
  const mquery = require('mquery');
@@ -67,7 +68,7 @@ const queryOptionMethods = new Set([
67
68
  /**
68
69
  * Query constructor used for building queries. You do not need
69
70
  * to instantiate a `Query` directly. Instead use Model functions like
70
- * [`Model.find()`](/docs/api/model.html#model_Model-find).
71
+ * [`Model.find()`](https://mongoosejs.com/docs/api/model.html#Model.find()).
71
72
  *
72
73
  * #### Example:
73
74
  *
@@ -812,7 +813,7 @@ Query.prototype.mod = function() {
812
813
  *
813
814
  * #### Note:
814
815
  *
815
- * As of Mongoose 3.7, `$geoWithin` is always used for queries. To change this behavior, see [Query.use$geoWithin](#query_Query-use%2524geoWithin).
816
+ * As of Mongoose 3.7, `$geoWithin` is always used for queries. To change this behavior, see [Query.use$geoWithin](https://mongoosejs.com/docs/api/query.html#Query.prototype.use$geoWithin).
816
817
  *
817
818
  * #### Note:
818
819
  *
@@ -999,7 +1000,7 @@ Query.prototype.projection = function(arg) {
999
1000
  /**
1000
1001
  * Specifies which document fields to include or exclude (also known as the query "projection")
1001
1002
  *
1002
- * When using string syntax, prefixing a path with `-` will flag that path as excluded. When a path does not have the `-` prefix, it is included. Lastly, if a path is prefixed with `+`, it forces inclusion of the path, which is useful for paths excluded at the [schema level](/docs/api/schematype.html#schematype_SchemaType-select).
1003
+ * When using string syntax, prefixing a path with `-` will flag that path as excluded. When a path does not have the `-` prefix, it is included. Lastly, if a path is prefixed with `+`, it forces inclusion of the path, which is useful for paths excluded at the [schema level](https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.select()).
1003
1004
  *
1004
1005
  * A projection _must_ be either inclusive or exclusive. In other words, you must
1005
1006
  * either list the fields to include (which excludes all others), or list the fields
@@ -1040,7 +1041,7 @@ Query.prototype.projection = function(arg) {
1040
1041
  * @instance
1041
1042
  * @param {Object|String|String[]} arg
1042
1043
  * @return {Query} this
1043
- * @see SchemaType /docs/api/schematype.html
1044
+ * @see SchemaType https://mongoosejs.com/docs/api/schematype.html
1044
1045
  * @api public
1045
1046
  */
1046
1047
 
@@ -1227,7 +1228,7 @@ Query.prototype.toString = function toString() {
1227
1228
  /**
1228
1229
  * Sets the [MongoDB session](https://www.mongodb.com/docs/manual/reference/server-sessions/)
1229
1230
  * associated with this query. Sessions are how you mark a query as part of a
1230
- * [transaction](/docs/transactions.html).
1231
+ * [transaction](https://mongoosejs.com/docs/transactions.html).
1231
1232
  *
1232
1233
  * Calling `session(null)` removes the session from this query.
1233
1234
  *
@@ -1240,8 +1241,8 @@ Query.prototype.toString = function toString() {
1240
1241
  * @memberOf Query
1241
1242
  * @instance
1242
1243
  * @param {ClientSession} [session] from `await conn.startSession()`
1243
- * @see Connection.prototype.startSession() /docs/api/connection.html#connection_Connection-startSession
1244
- * @see mongoose.startSession() /docs/api/mongoose.html#mongoose_Mongoose-startSession
1244
+ * @see Connection.prototype.startSession() https://mongoosejs.com/docs/api/connection.html#Connection.prototype.startSession()
1245
+ * @see mongoose.startSession() https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.startSession()
1245
1246
  * @return {Query} this
1246
1247
  * @api public
1247
1248
  */
@@ -1259,7 +1260,7 @@ Query.prototype.session = function session(v) {
1259
1260
  *
1260
1261
  * - `w`: Sets the specified number of `mongod` servers, or tag set of `mongod` servers, that must acknowledge this write before this write is considered successful.
1261
1262
  * - `j`: Boolean, set to `true` to request acknowledgement that this operation has been persisted to MongoDB's on-disk journal.
1262
- * - `wtimeout`: If [`w > 1`](#query_Query-w), the maximum amount of time to wait for this write to propagate through the replica set before this operation fails. The default is `0`, which means no timeout.
1263
+ * - `wtimeout`: If [`w > 1`](https://mongoosejs.com/docs/api/query.html#Query.prototype.w()), the maximum amount of time to wait for this write to propagate through the replica set before this operation fails. The default is `0`, which means no timeout.
1263
1264
  *
1264
1265
  * This option is only valid for operations that write to the database:
1265
1266
  *
@@ -1271,7 +1272,7 @@ Query.prototype.session = function session(v) {
1271
1272
  * - `updateOne()`
1272
1273
  * - `updateMany()`
1273
1274
  *
1274
- * Defaults to the schema's [`writeConcern` option](/docs/guide.html#writeConcern)
1275
+ * Defaults to the schema's [`writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern)
1275
1276
  *
1276
1277
  * #### Example:
1277
1278
  *
@@ -1312,7 +1313,7 @@ Query.prototype.writeConcern = function writeConcern(val) {
1312
1313
  * - `updateOne()`
1313
1314
  * - `updateMany()`
1314
1315
  *
1315
- * Defaults to the schema's [`writeConcern.w` option](/docs/guide.html#writeConcern)
1316
+ * Defaults to the schema's [`writeConcern.w` option](https://mongoosejs.com/docs/guide.html#writeConcern)
1316
1317
  *
1317
1318
  * #### Example:
1318
1319
  *
@@ -1356,7 +1357,7 @@ Query.prototype.w = function w(val) {
1356
1357
  * - `updateOne()`
1357
1358
  * - `updateMany()`
1358
1359
  *
1359
- * Defaults to the schema's [`writeConcern.j` option](/docs/guide.html#writeConcern)
1360
+ * Defaults to the schema's [`writeConcern.j` option](https://mongoosejs.com/docs/guide.html#writeConcern)
1360
1361
  *
1361
1362
  * #### Example:
1362
1363
  *
@@ -1384,7 +1385,7 @@ Query.prototype.j = function j(val) {
1384
1385
  };
1385
1386
 
1386
1387
  /**
1387
- * If [`w > 1`](#query_Query-w), the maximum amount of time to
1388
+ * If [`w > 1`](https://mongoosejs.com/docs/api/query.html#Query.prototype.w()), the maximum amount of time to
1388
1389
  * wait for this write to propagate through the replica set before this
1389
1390
  * operation fails. The default is `0`, which means no timeout.
1390
1391
  *
@@ -1398,7 +1399,7 @@ Query.prototype.j = function j(val) {
1398
1399
  * - `updateOne()`
1399
1400
  * - `updateMany()`
1400
1401
  *
1401
- * Defaults to the schema's [`writeConcern.wtimeout` option](/docs/guide.html#writeConcern)
1402
+ * Defaults to the schema's [`writeConcern.wtimeout` option](https://mongoosejs.com/docs/guide.html#writeConcern)
1402
1403
  *
1403
1404
  * #### Example:
1404
1405
  *
@@ -1508,7 +1509,6 @@ Query.prototype.getOptions = function() {
1508
1509
  * The following options are only for `find()`:
1509
1510
  *
1510
1511
  * - [tailable](https://www.mongodb.com/docs/manual/core/tailable-cursors/)
1511
- * - [sort](https://www.mongodb.com/docs/manual/reference/method/cursor.sort/)
1512
1512
  * - [limit](https://www.mongodb.com/docs/manual/reference/method/cursor.limit/)
1513
1513
  * - [skip](https://www.mongodb.com/docs/manual/reference/method/cursor.skip/)
1514
1514
  * - [allowDiskUse](https://www.mongodb.com/docs/manual/reference/method/cursor.allowDiskUse/)
@@ -1524,24 +1524,29 @@ Query.prototype.getOptions = function() {
1524
1524
  * - [timestamps](https://mongoosejs.com/docs/guide.html#timestamps): If `timestamps` is set in the schema, set this option to `false` to skip timestamps for that particular update. Has no effect if `timestamps` is not enabled in the schema options.
1525
1525
  * - overwriteDiscriminatorKey: allow setting the discriminator key in the update. Will use the correct discriminator schema if the update changes the discriminator key.
1526
1526
  *
1527
- * The following options are only for `find()`, `findOne()`, `findById()`, `findOneAndUpdate()`, and `findByIdAndUpdate()`:
1527
+ * The following options are only for `find()`, `findOne()`, `findById()`, `findOneAndUpdate()`, `findOneAndReplace()`, `findOneAndDelete()`, and `findByIdAndUpdate()`:
1528
1528
  *
1529
- * - [lean](#query_Query-lean)
1530
- * - [populate](/docs/populate.html)
1531
- * - [projection](#query_Query-projection)
1529
+ * - [lean](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean())
1530
+ * - [populate](https://mongoosejs.com/docs/populate.html)
1531
+ * - [projection](https://mongoosejs.com/docs/api/query.html#Query.prototype.projection())
1532
1532
  * - sanitizeProjection
1533
+ * - useBigInt64
1533
1534
  *
1534
1535
  * The following options are only for all operations **except** `updateOne()`, `updateMany()`, `deleteOne()`, and `deleteMany()`:
1535
1536
  *
1536
1537
  * - [maxTimeMS](https://www.mongodb.com/docs/manual/reference/operator/meta/maxTimeMS/)
1537
1538
  *
1539
+ * The following options are for `find()`, `findOne()`, `findOneAndUpdate()`, `findOneAndRemove()`, `findOneAndDelete()`, `updateOne()`, and `deleteOne()`:
1540
+ *
1541
+ * - [sort](https://www.mongodb.com/docs/manual/reference/method/cursor.sort/)
1542
+ *
1538
1543
  * The following options are for `findOneAndUpdate()` and `findOneAndRemove()`
1539
1544
  *
1540
1545
  * - rawResult
1541
1546
  *
1542
1547
  * The following options are for all operations:
1543
1548
  *
1544
- * - [strict](/docs/guide.html#strict)
1549
+ * - [strict](https://mongoosejs.com/docs/guide.html#strict)
1545
1550
  * - [collation](https://www.mongodb.com/docs/manual/reference/collation/)
1546
1551
  * - [session](https://www.mongodb.com/docs/manual/reference/server-sessions/)
1547
1552
  * - [explain](https://www.mongodb.com/docs/manual/reference/method/cursor.explain/)
@@ -1967,7 +1972,7 @@ Query.prototype._optionsForExec = function(model) {
1967
1972
  * Sets the lean option.
1968
1973
  *
1969
1974
  * Documents returned from queries with the `lean` option enabled are plain
1970
- * javascript objects, not [Mongoose Documents](/docs/api/document.html). They have no
1975
+ * javascript objects, not [Mongoose Documents](https://mongoosejs.com/docs/api/document.html). They have no
1971
1976
  * `save` method, getters/setters, virtuals, or other Mongoose features.
1972
1977
  *
1973
1978
  * #### Example:
@@ -1979,9 +1984,9 @@ Query.prototype._optionsForExec = function(model) {
1979
1984
  * const docs = await Model.find().lean();
1980
1985
  * docs[0] instanceof mongoose.Document; // false
1981
1986
  *
1982
- * [Lean is great for high-performance, read-only cases](/docs/tutorials/lean.html),
1987
+ * [Lean is great for high-performance, read-only cases](https://mongoosejs.com/docs/tutorials/lean.html),
1983
1988
  * especially when combined
1984
- * with [cursors](/docs/queries.html#streaming).
1989
+ * with [cursors](https://mongoosejs.com/docs/queries.html#streaming).
1985
1990
  *
1986
1991
  * If you need virtuals, getters/setters, or defaults with `lean()`, you need
1987
1992
  * to use a plugin. See:
@@ -2129,11 +2134,11 @@ Query.prototype._unsetCastError = function _unsetCastError() {
2129
2134
  * Getter/setter around the current mongoose-specific options for this query
2130
2135
  * Below are the current Mongoose-specific options.
2131
2136
  *
2132
- * - `populate`: an array representing what paths will be populated. Should have one entry for each call to [`Query.prototype.populate()`](#query_Query-populate)
2133
- * - `lean`: if truthy, Mongoose will not [hydrate](/docs/api/model.html#model_Model-hydrate) any documents that are returned from this query. See [`Query.prototype.lean()`](#query_Query-lean) for more information.
2134
- * - `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.
2135
- * - `strictQuery`: controls how Mongoose handles keys that aren't in the schema for the query `filter`. This option is `false` by default, 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.
2136
- * - `nearSphere`: use `$nearSphere` instead of `near()`. See the [`Query.prototype.nearSphere()` docs](#query_Query-nearSphere)
2137
+ * - `populate`: an array representing what paths will be populated. Should have one entry for each call to [`Query.prototype.populate()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.populate())
2138
+ * - `lean`: if truthy, Mongoose will not [hydrate](https://mongoosejs.com/docs/api/model.html#Model.hydrate()) any documents that are returned from this query. See [`Query.prototype.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) for more information.
2139
+ * - `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](https://mongoosejs.com/docs/guide.html#strict) for more information.
2140
+ * - `strictQuery`: controls how Mongoose handles keys that aren't in the schema for the query `filter`. This option is `false` by default, which means Mongoose will allow `Model.find({ foo: 'bar' })` even if `foo` is not in the schema. See the [`strictQuery` docs](https://mongoosejs.com/docs/guide.html#strictQuery) for more information.
2141
+ * - `nearSphere`: use `$nearSphere` instead of `near()`. See the [`Query.prototype.nearSphere()` docs](https://mongoosejs.com/docs/api/query.html#Query.prototype.nearSphere())
2137
2142
  *
2138
2143
  * Mongoose maintains a separate object for internal options because
2139
2144
  * Mongoose sends `Query.prototype.options` to the MongoDB server, and the
@@ -2268,7 +2273,7 @@ Query.prototype._find = async function _find() {
2268
2273
  * Find all documents that match `selector`. The result will be an array of documents.
2269
2274
  *
2270
2275
  * If there are too many documents in the result to fit in memory, use
2271
- * [`Query.prototype.cursor()`](#query_Query-cursor)
2276
+ * [`Query.prototype.cursor()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.cursor())
2272
2277
  *
2273
2278
  * #### Example:
2274
2279
  *
@@ -2509,10 +2514,10 @@ Query.prototype._findOne = async function _findOne() {
2509
2514
  *
2510
2515
  * @param {Object} [filter] mongodb selector
2511
2516
  * @param {Object} [projection] optional fields to return
2512
- * @param {Object} [options] see [`setOptions()`](#query_Query-setOptions)
2517
+ * @param {Object} [options] see [`setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
2513
2518
  * @return {Query} this
2514
2519
  * @see findOne https://www.mongodb.com/docs/manual/reference/method/db.collection.findOne/
2515
- * @see Query.select #query_Query-select
2520
+ * @see Query.select https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
2516
2521
  * @api public
2517
2522
  */
2518
2523
 
@@ -2626,8 +2631,8 @@ Query.prototype._estimatedDocumentCount = async function _estimatedDocumentCount
2626
2631
  * Specifies this query as a `count` query.
2627
2632
  *
2628
2633
  * This method is deprecated. If you want to count the number of documents in
2629
- * a collection, e.g. `count({})`, use the [`estimatedDocumentCount()` function](#query_Query-estimatedDocumentCount)
2630
- * instead. Otherwise, use the [`countDocuments()`](#query_Query-countDocuments) function instead.
2634
+ * a collection, e.g. `count({})`, use the [`estimatedDocumentCount()` function](https://mongoosejs.com/docs/api/query.html#Query.prototype.estimatedDocumentCount())
2635
+ * instead. Otherwise, use the [`countDocuments()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.countDocuments()) function instead.
2631
2636
  *
2632
2637
  * This function triggers the following middleware.
2633
2638
  *
@@ -2899,7 +2904,7 @@ Query.prototype.sort = function(arg) {
2899
2904
  * res.deletedCount;
2900
2905
  *
2901
2906
  * @param {Object|Query} [filter] mongodb selector
2902
- * @param {Object} [options] optional see [`Query.prototype.setOptions()`](#query_Query-setOptions)
2907
+ * @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
2903
2908
  * @return {Query} this
2904
2909
  * @see DeleteResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/DeleteResult.html
2905
2910
  * @see deleteOne https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#deleteOne
@@ -2975,7 +2980,7 @@ Query.prototype._deleteOne = async function _deleteOne() {
2975
2980
  * res.deletedCount;
2976
2981
  *
2977
2982
  * @param {Object|Query} [filter] mongodb selector
2978
- * @param {Object} [options] optional see [`Query.prototype.setOptions()`](#query_Query-setOptions)
2983
+ * @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
2979
2984
  * @return {Query} this
2980
2985
  * @see DeleteResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/DeleteResult.html
2981
2986
  * @see deleteMany https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#deleteMany
@@ -3106,7 +3111,7 @@ function prepareDiscriminatorCriteria(query) {
3106
3111
  * - `fields`: {Object|String} - Field selection. Equivalent to `.select(fields).findOneAndUpdate()`
3107
3112
  * - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
3108
3113
  * - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
3109
- * - `runValidators`: if true, runs [update validators](/docs/validation.html#update-validators) on this command. Update validators validate the update operation against the model's schema.
3114
+ * - `runValidators`: if true, runs [update validators](https://mongoosejs.com/docs/validation.html#update-validators) on this command. Update validators validate the update operation against the model's schema.
3110
3115
  * - `setDefaultsOnInsert`: `true` by default. If `setDefaultsOnInsert` and `upsert` are true, mongoose will apply the [defaults](https://mongoosejs.com/docs/defaults.html) specified in the model's schema if a new document is created.
3111
3116
  * - `rawResult`: if true, returns the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html)
3112
3117
  *
@@ -3125,15 +3130,15 @@ function prepareDiscriminatorCriteria(query) {
3125
3130
  * @param {Object} [options]
3126
3131
  * @param {Boolean} [options.rawResult] if true, returns the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html)
3127
3132
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3128
- * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
3133
+ * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3129
3134
  * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
3130
3135
  * @param {Boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied.
3131
- * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](#query_Query-lean) and [the Mongoose lean tutorial](/docs/tutorials/lean.html).
3132
- * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
3136
+ * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3137
+ * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3133
3138
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3134
- * @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.
3139
+ * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/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.
3135
3140
  * @param {Boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
3136
- * @see Tutorial /docs/tutorials/findoneandupdate.html
3141
+ * @see Tutorial https://mongoosejs.com/docs/tutorials/findoneandupdate.html
3137
3142
  * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
3138
3143
  * @see ModifyResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html
3139
3144
  * @see findOneAndUpdate https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#findOneAndUpdate
@@ -3309,7 +3314,7 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3309
3314
  * @param {Object} [conditions]
3310
3315
  * @param {Object} [options]
3311
3316
  * @param {Boolean} [options.rawResult] if true, returns the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html)
3312
- * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
3317
+ * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3313
3318
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3314
3319
  * @return {Query} this
3315
3320
  * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
@@ -3369,7 +3374,7 @@ Query.prototype.findOneAndRemove = function(conditions, options) {
3369
3374
  * @param {Object} [conditions]
3370
3375
  * @param {Object} [options]
3371
3376
  * @param {Boolean} [options.rawResult] if true, returns the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html)
3372
- * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
3377
+ * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3373
3378
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3374
3379
  * @return {Query} this
3375
3380
  * @see findAndModify command https://www.mongodb.com/docs/manual/reference/command/findAndModify/
@@ -3474,13 +3479,13 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
3474
3479
  * @param {Object} [replacement]
3475
3480
  * @param {Object} [options]
3476
3481
  * @param {Boolean} [options.rawResult] if true, returns the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html)
3477
- * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
3482
+ * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3478
3483
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3479
3484
  * @param {Boolean} [options.new=false] By default, `findOneAndUpdate()` returns the document as it was **before** `update` was applied. If you set `new: true`, `findOneAndUpdate()` will instead give you the object after `update` was applied.
3480
- * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](#query_Query-lean) and [the Mongoose lean tutorial](/docs/tutorials/lean.html).
3481
- * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
3485
+ * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and [the Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
3486
+ * @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3482
3487
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3483
- * @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.
3488
+ * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/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.
3484
3489
  * @param {Boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
3485
3490
  * @return {Query} this
3486
3491
  * @api public
@@ -3858,7 +3863,7 @@ Query.prototype.validate = async function validate(castedDoc, options, isOverwri
3858
3863
  /**
3859
3864
  * Execute an updateMany query
3860
3865
  *
3861
- * @see Model.update #model_Model-update
3866
+ * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
3862
3867
  * @method _updateMany
3863
3868
  * @memberOf Query
3864
3869
  * @instance
@@ -3871,7 +3876,7 @@ Query.prototype._updateMany = async function _updateMany() {
3871
3876
  /**
3872
3877
  * Execute an updateOne query
3873
3878
  *
3874
- * @see Model.update #model_Model-update
3879
+ * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
3875
3880
  * @method _updateOne
3876
3881
  * @memberOf Query
3877
3882
  * @instance
@@ -3884,7 +3889,7 @@ Query.prototype._updateOne = async function _updateOne() {
3884
3889
  /**
3885
3890
  * Execute a replaceOne query
3886
3891
  *
3887
- * @see Model.replaceOne #model_Model-replaceOne
3892
+ * @see Model.replaceOne https://mongoosejs.com/docs/api/model.html#Model.replaceOne()
3888
3893
  * @method _replaceOne
3889
3894
  * @memberOf Query
3890
3895
  * @instance
@@ -3917,11 +3922,11 @@ Query.prototype._replaceOne = async function _replaceOne() {
3917
3922
  * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
3918
3923
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3919
3924
  * @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
3920
- * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](/docs/guide.html#writeConcern)
3921
- * @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.
3925
+ * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
3926
+ * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
3922
3927
  * @param {Function} [callback] params are (error, writeOpResult)
3923
3928
  * @return {Query} this
3924
- * @see Model.update #model_Model-update
3929
+ * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
3925
3930
  * @see Query docs https://mongoosejs.com/docs/queries.html
3926
3931
  * @see update https://www.mongodb.com/docs/manual/reference/method/db.collection.update/
3927
3932
  * @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
@@ -3985,11 +3990,11 @@ Query.prototype.updateMany = function(conditions, doc, options, callback) {
3985
3990
  * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
3986
3991
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3987
3992
  * @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
3988
- * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](/docs/guide.html#writeConcern)
3989
- * @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.
3993
+ * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
3994
+ * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/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.
3990
3995
  * @param {Function} [callback] params are (error, writeOpResult)
3991
3996
  * @return {Query} this
3992
- * @see Model.update #model_Model-update
3997
+ * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
3993
3998
  * @see Query docs https://mongoosejs.com/docs/queries.html
3994
3999
  * @see update https://www.mongodb.com/docs/manual/reference/method/db.collection.update/
3995
4000
  * @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
@@ -4051,11 +4056,11 @@ Query.prototype.updateOne = function(conditions, doc, options, callback) {
4051
4056
  * @param {Boolean} [options.multipleCastError] by default, mongoose only returns the first error that occurred in casting the query. Turn on this option to aggregate all the cast errors.
4052
4057
  * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
4053
4058
  * @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
4054
- * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](/docs/guide.html#writeConcern)
4055
- * @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.
4059
+ * @param {Object} [options.writeConcern=null] sets the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/) for replica sets. Overrides the [schema-level write concern](https://mongoosejs.com/docs/guide.html#writeConcern)
4060
+ * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Does nothing if schema-level timestamps are not set.
4056
4061
  * @param {Function} [callback] params are (error, writeOpResult)
4057
4062
  * @return {Query} this
4058
- * @see Model.update #model_Model-update
4063
+ * @see Model.update https://mongoosejs.com/docs/api/model.html#Model.update()
4059
4064
  * @see Query docs https://mongoosejs.com/docs/queries.html
4060
4065
  * @see update https://www.mongodb.com/docs/manual/reference/method/db.collection.update/
4061
4066
  * @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
@@ -4265,6 +4270,17 @@ function _orFailError(err, query) {
4265
4270
  return err;
4266
4271
  }
4267
4272
 
4273
+ /**
4274
+ * Wrapper function to call isPathSelectedInclusive on a query.
4275
+ * @param {String} path
4276
+ * @return {Boolean}
4277
+ * @api public
4278
+ */
4279
+
4280
+ Query.prototype.isPathSelectedInclusive = function(path) {
4281
+ return isPathSelectedInclusive(this._fields, path);
4282
+ };
4283
+
4268
4284
  /**
4269
4285
  * Executes the query
4270
4286
  *
@@ -4500,7 +4516,7 @@ Query.prototype[Symbol.toStringTag] = function toString() {
4500
4516
  };
4501
4517
 
4502
4518
  /**
4503
- * Add pre [middleware](/docs/middleware.html) to this query instance. Doesn't affect
4519
+ * Add pre [middleware](https://mongoosejs.com/docs/middleware.html) to this query instance. Doesn't affect
4504
4520
  * other queries.
4505
4521
  *
4506
4522
  * #### Example:
@@ -4526,7 +4542,7 @@ Query.prototype.pre = function(fn) {
4526
4542
  };
4527
4543
 
4528
4544
  /**
4529
- * Add post [middleware](/docs/middleware.html) to this query instance. Doesn't affect
4545
+ * Add post [middleware](https://mongoosejs.com/docs/middleware.html) to this query instance. Doesn't affect
4530
4546
  * other queries.
4531
4547
  *
4532
4548
  * #### Example:
@@ -4645,14 +4661,14 @@ Query.prototype._castUpdate = function _castUpdate(obj, overwrite) {
4645
4661
  * @param {Object} [options] Options for the population query (sort, etc)
4646
4662
  * @param {String} [options.path=null] The path to populate.
4647
4663
  * @param {boolean} [options.retainNullValues=false] by default, Mongoose removes null and undefined values from populated arrays. Use this option to make `populate()` retain `null` and `undefined` array entries.
4648
- * @param {boolean} [options.getters=false] if true, Mongoose will call any getters defined on the `localField`. By default, Mongoose gets the raw value of `localField`. For example, you would need to set this option to `true` if you wanted to [add a `lowercase` getter to your `localField`](/docs/schematypes.html#schematype-options).
4664
+ * @param {boolean} [options.getters=false] if true, Mongoose will call any getters defined on the `localField`. By default, Mongoose gets the raw value of `localField`. For example, you would need to set this option to `true` if you wanted to [add a `lowercase` getter to your `localField`](https://mongoosejs.com/docs/schematypes.html#schematype-options).
4649
4665
  * @param {boolean} [options.clone=false] When you do `BlogPost.find().populate('author')`, blog posts with the same author will share 1 copy of an `author` doc. Enable this option to make Mongoose clone populated docs before assigning them.
4650
4666
  * @param {Object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://www.mongodb.com/docs/manual/tutorial/query-documents/), or a function that returns a filter object.
4651
4667
  * @param {Function} [options.transform=null] Function that Mongoose will call on every populated document that allows you to transform the populated document.
4652
4668
  * @param {Object} [options.options=null] Additional options like `limit` and `lean`.
4653
- * @see population /docs/populate.html
4654
- * @see Query#select #query_Query-select
4655
- * @see Model.populate #model_Model-populate
4669
+ * @see population https://mongoosejs.com/docs/populate.html
4670
+ * @see Query#select https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
4671
+ * @see Model.populate https://mongoosejs.com/docs/api/model.html#Model.populate()
4656
4672
  * @return {Query} this
4657
4673
  * @api public
4658
4674
  */
@@ -4920,7 +4936,7 @@ Query.prototype._applyPaths = function applyPaths() {
4920
4936
  *
4921
4937
  * @return {QueryCursor}
4922
4938
  * @param {Object} [options]
4923
- * @see QueryCursor /docs/api/querycursor.html
4939
+ * @see QueryCursor https://mongoosejs.com/docs/api/querycursor.html
4924
4940
  * @api public
4925
4941
  */
4926
4942
 
@@ -5171,7 +5187,7 @@ Query.prototype.near = function() {
5171
5187
  * query.where('loc').near({ center: [10, 10], spherical: true });
5172
5188
  *
5173
5189
  * @deprecated
5174
- * @see near() #query_Query-near
5190
+ * @see near() https://mongoosejs.com/docs/api/query.html#Query.prototype.near()
5175
5191
  * @see $near https://www.mongodb.com/docs/manual/reference/operator/near/
5176
5192
  * @see $nearSphere https://www.mongodb.com/docs/manual/reference/operator/nearSphere/
5177
5193
  * @see $maxDistance https://www.mongodb.com/docs/manual/reference/operator/maxDistance/
@@ -5226,7 +5242,7 @@ if (Symbol.asyncIterator != null) {
5226
5242
  * @memberOf Query
5227
5243
  * @instance
5228
5244
  * @param {String|Array} [path]
5229
- * @param {Array|Object} [coordinatePairs...]
5245
+ * @param {...Array|Object} [coordinatePairs]
5230
5246
  * @return {Query} this
5231
5247
  * @see $polygon https://www.mongodb.com/docs/manual/reference/operator/polygon/
5232
5248
  * @see MongoDB Geospatial Indexing https://www.mongodb.com/docs/manual/core/geospatial-indexes/
@@ -5248,7 +5264,7 @@ if (Symbol.asyncIterator != null) {
5248
5264
  * @memberOf Query
5249
5265
  * @instance
5250
5266
  * @see $box https://www.mongodb.com/docs/manual/reference/operator/box/
5251
- * @see within() Query#within #query_Query-within
5267
+ * @see within() Query#within https://mongoosejs.com/docs/api/query.html#Query.prototype.within()
5252
5268
  * @see MongoDB Geospatial Indexing https://www.mongodb.com/docs/manual/core/geospatial-indexes/
5253
5269
  * @param {Object|Array<Number>} val1 Lower Left Coordinates OR a object of lower-left(ll) and upper-right(ur) Coordinates
5254
5270
  * @param {Array<Number>} [val2] Upper Right Coordinates
@@ -5305,9 +5321,9 @@ Query.prototype.box = function(ll, ur) {
5305
5321
  */
5306
5322
 
5307
5323
  /**
5308
- * _DEPRECATED_ Alias for [circle](#query_Query-circle)
5324
+ * _DEPRECATED_ Alias for [circle](https://mongoosejs.com/docs/api/query.html#Query.prototype.circle())
5309
5325
  *
5310
- * **Deprecated.** Use [circle](#query_Query-circle) instead.
5326
+ * **Deprecated.** Use [circle](https://mongoosejs.com/docs/api/query.html#Query.prototype.circle()) instead.
5311
5327
  *
5312
5328
  * @deprecated
5313
5329
  * @method center
@@ -5321,7 +5337,7 @@ Query.prototype.center = Query.base.circle;
5321
5337
  /**
5322
5338
  * _DEPRECATED_ Specifies a `$centerSphere` condition
5323
5339
  *
5324
- * **Deprecated.** Use [circle](#query_Query-circle) instead.
5340
+ * **Deprecated.** Use [circle](https://mongoosejs.com/docs/api/query.html#Query.prototype.circle()) instead.
5325
5341
  *
5326
5342
  * #### Example:
5327
5343
  *
@@ -296,7 +296,7 @@ SubdocumentPath.prototype.doValidateSync = function(value, scope, options) {
296
296
  * @param {String} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
297
297
  * @param {Boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
298
298
  * @return {Function} the constructor Mongoose will use for creating instances of this discriminator model
299
- * @see discriminators /docs/discriminators.html
299
+ * @see discriminators https://mongoosejs.com/docs/discriminators.html
300
300
  * @api public
301
301
  */
302
302