mongoose 6.9.1 → 6.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +39 -39
- package/lib/connection.js +5 -5
- package/lib/cursor/AggregationCursor.js +1 -1
- package/lib/cursor/QueryCursor.js +1 -1
- package/lib/document.js +11 -11
- package/lib/drivers/node-mongodb-native/collection.js +1 -1
- package/lib/error/index.js +21 -10
- package/lib/error/serverSelection.js +1 -1
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/helpers/query/castUpdate.js +0 -12
- package/lib/index.js +7 -7
- package/lib/model.js +61 -61
- package/lib/query.js +139 -140
- package/lib/schema/SubdocumentPath.js +1 -1
- package/lib/schema/operators/text.js +1 -1
- package/lib/schema/uuid.js +3 -3
- package/lib/schema.js +1 -1
- package/lib/schematype.js +1 -1
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +4 -3
- package/lib/types/buffer.js +1 -1
- package/lib/virtualtype.js +1 -1
- package/package.json +4 -2
- package/types/aggregate.d.ts +1 -1
- package/types/connection.d.ts +4 -4
- package/types/error.d.ts +5 -0
- package/types/expressions.d.ts +153 -153
- package/types/index.d.ts +3 -3
- package/types/models.d.ts +2 -2
- package/types/mongooseoptions.d.ts +1 -1
- package/types/pipelinestage.d.ts +34 -34
- package/types/query.d.ts +10 -10
- package/types/schematypes.d.ts +1 -1
- package/types/session.d.ts +4 -4
package/lib/model.js
CHANGED
|
@@ -82,12 +82,12 @@ const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* A Model is a class that's your primary tool for interacting with MongoDB.
|
|
85
|
-
* An instance of a Model is called a [Document](
|
|
85
|
+
* An instance of a Model is called a [Document](/docs/api/document.html#Document).
|
|
86
86
|
*
|
|
87
87
|
* In Mongoose, the term "Model" refers to subclasses of the `mongoose.Model`
|
|
88
88
|
* class. You should not use the `mongoose.Model` class directly. The
|
|
89
|
-
* [`mongoose.model()`](
|
|
90
|
-
* [`connection.model()`](
|
|
89
|
+
* [`mongoose.model()`](/docs/api/mongoose.html#mongoose_Mongoose-model) and
|
|
90
|
+
* [`connection.model()`](/docs/api/connection.html#connection_Connection-model) functions
|
|
91
91
|
* create subclasses of `mongoose.Model` as shown below.
|
|
92
92
|
*
|
|
93
93
|
* #### Example:
|
|
@@ -103,7 +103,7 @@ const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
|
|
|
103
103
|
* const userFromDb = await UserModel.findOne({ name: 'Foo' });
|
|
104
104
|
*
|
|
105
105
|
* @param {Object} doc values for initial set
|
|
106
|
-
* @param {Object} [fields] optional object containing the fields that were selected in the query which returned this document. You do **not** need to set this parameter to ensure Mongoose handles your [query projection](
|
|
106
|
+
* @param {Object} [fields] optional object containing the fields that were selected in the query which returned this document. You do **not** need to set this parameter to ensure Mongoose handles your [query projection](/docs/api/query.html#query_Query-select).
|
|
107
107
|
* @param {Boolean} [skipId=false] optional boolean. If true, mongoose doesn't add an `_id` field to the document.
|
|
108
108
|
* @inherits Document https://mongoosejs.com/docs/api/document.html
|
|
109
109
|
* @event `error`: If listening to this event, 'error' is emitted when a document was saved without passing a callback and an `error` occurred. If not listening, the event bubbles to the connection used to create this Model.
|
|
@@ -477,17 +477,17 @@ function generateVersionError(doc, modifiedPaths) {
|
|
|
477
477
|
* newProduct === product; // true
|
|
478
478
|
*
|
|
479
479
|
* @param {Object} [options] options optional options
|
|
480
|
-
* @param {Session} [options.session=null] the [session](https://
|
|
480
|
+
* @param {Session} [options.session=null] the [session](https://www.mongodb.com/docs/manual/reference/server-sessions/) associated with this save operation. If not specified, defaults to the [document's associated session](/docs/api/document.html#document_Document-$session).
|
|
481
481
|
* @param {Object} [options.safe] (DEPRECATED) overrides [schema's safe option](https://mongoosejs.com//docs/guide.html#safe). Use the `w` option instead.
|
|
482
482
|
* @param {Boolean} [options.validateBeforeSave] set to false to save without validating.
|
|
483
483
|
* @param {Boolean} [options.validateModifiedOnly=false] if `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
|
|
484
|
-
* @param {Number|String} [options.w] set the [write concern](https://
|
|
485
|
-
* @param {Boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://
|
|
486
|
-
* @param {Number} [options.wtimeout] sets a [timeout for the write concern](https://
|
|
487
|
-
* @param {Boolean} [options.checkKeys=true] the MongoDB driver prevents you from saving keys that start with '$' or contain '.' by default. Set this option to `false` to skip that check. See [restrictions on field names](https://
|
|
488
|
-
* @param {Boolean} [options.timestamps=true] if `false` and [timestamps](
|
|
484
|
+
* @param {Number|String} [options.w] set the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#w-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
|
|
485
|
+
* @param {Boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
|
|
486
|
+
* @param {Number} [options.wtimeout] sets a [timeout for the write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern).
|
|
487
|
+
* @param {Boolean} [options.checkKeys=true] the MongoDB driver prevents you from saving keys that start with '$' or contain '.' by default. Set this option to `false` to skip that check. See [restrictions on field names](https://www.mongodb.com/docs/manual/reference/limits/#Restrictions-on-Field-Names)
|
|
488
|
+
* @param {Boolean} [options.timestamps=true] if `false` and [timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
|
|
489
489
|
* @param {Function} [fn] optional callback
|
|
490
|
-
* @throws {DocumentNotFoundError} if this [save updates an existing document](api/document.html#document_Document-isNew) but the document doesn't exist in the database. For example, you will get this error if the document is [deleted between when you retrieved the document and when you saved it](documents.html#updating).
|
|
490
|
+
* @throws {DocumentNotFoundError} if this [save updates an existing document](/docs/api/document.html#document_Document-isNew) but the document doesn't exist in the database. For example, you will get this error if the document is [deleted between when you retrieved the document and when you saved it](documents.html#updating).
|
|
491
491
|
* @return {Promise|undefined} Returns undefined if used with callback or a Promise otherwise.
|
|
492
492
|
* @api public
|
|
493
493
|
* @see middleware https://mongoosejs.com/docs/middleware.html
|
|
@@ -991,7 +991,7 @@ Model.prototype.$__where = function _where(where) {
|
|
|
991
991
|
* console.log(foundProduct) // null
|
|
992
992
|
*
|
|
993
993
|
* @param {Object} [options]
|
|
994
|
-
* @param {Session} [options.session=null] the [session](https://
|
|
994
|
+
* @param {Session} [options.session=null] the [session](https://www.mongodb.com/docs/manual/reference/server-sessions/) associated with this operation. If not specified, defaults to the [document's associated session](/docs/api/document.html#document_Document-$session).
|
|
995
995
|
* @param {function(err,product)} [fn] optional callback
|
|
996
996
|
* @return {Promise} Promise
|
|
997
997
|
* @api public
|
|
@@ -1308,7 +1308,7 @@ for (const i in EventEmitter.prototype) {
|
|
|
1308
1308
|
}
|
|
1309
1309
|
|
|
1310
1310
|
/**
|
|
1311
|
-
* This function is responsible for building [indexes](https://
|
|
1311
|
+
* This function is responsible for building [indexes](https://www.mongodb.com/docs/manual/indexes/),
|
|
1312
1312
|
* unless [`autoIndex`](https://mongoosejs.com/docs/guide.html#autoIndex) is turned off.
|
|
1313
1313
|
*
|
|
1314
1314
|
* Mongoose calls this function automatically when a model is created using
|
|
@@ -1399,7 +1399,7 @@ Model.init = function init(callback) {
|
|
|
1399
1399
|
* created. Use this method to create the collection explicitly.
|
|
1400
1400
|
*
|
|
1401
1401
|
* Note 1: You may need to call this before starting a transaction
|
|
1402
|
-
* See https://
|
|
1402
|
+
* See https://www.mongodb.com/docs/manual/core/transactions/#transactions-and-operations
|
|
1403
1403
|
*
|
|
1404
1404
|
* Note 2: You don't have to call this if your schema contains index or unique field.
|
|
1405
1405
|
* In that case, just use `Model.init()`
|
|
@@ -2088,7 +2088,7 @@ Model.translateAliases = function translateAliases(fields) {
|
|
|
2088
2088
|
* @deprecated
|
|
2089
2089
|
* @param {Object} conditions
|
|
2090
2090
|
* @param {Object} [options]
|
|
2091
|
-
* @param {Session} [options.session=null] the [session](https://
|
|
2091
|
+
* @param {Session} [options.session=null] the [session](https://www.mongodb.com/docs/manual/reference/server-sessions/) associated with this operation.
|
|
2092
2092
|
* @param {Function} [callback]
|
|
2093
2093
|
* @return {Query}
|
|
2094
2094
|
* @api public
|
|
@@ -2400,7 +2400,7 @@ Model.estimatedDocumentCount = function estimatedDocumentCount(options, callback
|
|
|
2400
2400
|
* });
|
|
2401
2401
|
*
|
|
2402
2402
|
* If you want to count all documents in a large collection,
|
|
2403
|
-
* use the [`estimatedDocumentCount()` function](
|
|
2403
|
+
* use the [`estimatedDocumentCount()` function](#model_Model-estimatedDocumentCount)
|
|
2404
2404
|
* instead. If you call `countDocuments({})`, MongoDB will always execute
|
|
2405
2405
|
* a full collection scan and **not** use any indexes.
|
|
2406
2406
|
*
|
|
@@ -2409,9 +2409,9 @@ Model.estimatedDocumentCount = function estimatedDocumentCount(options, callback
|
|
|
2409
2409
|
* Below are the operators that `count()` supports but `countDocuments()` does not,
|
|
2410
2410
|
* and the suggested replacement:
|
|
2411
2411
|
*
|
|
2412
|
-
* - `$where`: [`$expr`](https://
|
|
2413
|
-
* - `$near`: [`$geoWithin`](https://
|
|
2414
|
-
* - `$nearSphere`: [`$geoWithin`](https://
|
|
2412
|
+
* - `$where`: [`$expr`](https://www.mongodb.com/docs/manual/reference/operator/query/expr/)
|
|
2413
|
+
* - `$near`: [`$geoWithin`](https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/) with [`$center`](https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center)
|
|
2414
|
+
* - `$nearSphere`: [`$geoWithin`](https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/) with [`$centerSphere`](https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere)
|
|
2415
2415
|
*
|
|
2416
2416
|
* @param {Object} filter
|
|
2417
2417
|
* @param {Function} [callback]
|
|
@@ -2445,8 +2445,8 @@ Model.countDocuments = function countDocuments(conditions, options, callback) {
|
|
|
2445
2445
|
* Counts number of documents that match `filter` in a database collection.
|
|
2446
2446
|
*
|
|
2447
2447
|
* This method is deprecated. If you want to count the number of documents in
|
|
2448
|
-
* a collection, e.g. `count({})`, use the [`estimatedDocumentCount()` function](
|
|
2449
|
-
* instead. Otherwise, use the [`countDocuments()`](
|
|
2448
|
+
* a collection, e.g. `count({})`, use the [`estimatedDocumentCount()` function](#model_Model-estimatedDocumentCount)
|
|
2449
|
+
* instead. Otherwise, use the [`countDocuments()`](#model_Model-countDocuments) function instead.
|
|
2450
2450
|
*
|
|
2451
2451
|
* #### Example:
|
|
2452
2452
|
*
|
|
@@ -2615,7 +2615,7 @@ Model.$where = function $where() {
|
|
|
2615
2615
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2616
2616
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2617
2617
|
* @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.
|
|
2618
|
-
* @param {Boolean} [options.overwrite=false] By default, if you don't include any [update operators](https://
|
|
2618
|
+
* @param {Boolean} [options.overwrite=false] By default, if you don't include any [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/) in `update`, Mongoose will wrap `update` in `$set` for you. This prevents you from accidentally overwriting the document. This option tells Mongoose to skip adding `$set`. An alternative to this would be using [Model.findOneAndReplace(conditions, update, options, callback)](#model_Model-findOneAndReplace).
|
|
2619
2619
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
2620
2620
|
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#query_Query-select)
|
|
2621
2621
|
* @param {Boolean} [options.new=false] if true, return the modified document rather than the original
|
|
@@ -2628,7 +2628,7 @@ Model.$where = function $where() {
|
|
|
2628
2628
|
* @param {Function} [callback]
|
|
2629
2629
|
* @return {Query}
|
|
2630
2630
|
* @see Tutorial /docs/tutorials/findoneandupdate.html
|
|
2631
|
-
* @see mongodb https://www.mongodb.
|
|
2631
|
+
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
2632
2632
|
* @api public
|
|
2633
2633
|
*/
|
|
2634
2634
|
|
|
@@ -2748,7 +2748,7 @@ function _decorateUpdateWithVersionKey(update, options, versionKey) {
|
|
|
2748
2748
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2749
2749
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2750
2750
|
* @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.
|
|
2751
|
-
* @param {Boolean} [options.overwrite=false] By default, if you don't include any [update operators](https://
|
|
2751
|
+
* @param {Boolean} [options.overwrite=false] By default, if you don't include any [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/) in `update`, Mongoose will wrap `update` in `$set` for you. This prevents you from accidentally overwriting the document. This option tells Mongoose to skip adding `$set`. An alternative to this would be using [Model.findOneAndReplace({ _id: id }, update, options, callback)](#model_Model-findOneAndReplace).
|
|
2752
2752
|
* @param {Object|String} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2753
2753
|
* @param {Boolean} [options.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
|
|
2754
2754
|
* @param {Boolean} [options.setDefaultsOnInsert=true] 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
|
|
@@ -2759,7 +2759,7 @@ function _decorateUpdateWithVersionKey(update, options, versionKey) {
|
|
|
2759
2759
|
* @param {Function} [callback]
|
|
2760
2760
|
* @return {Query}
|
|
2761
2761
|
* @see Model.findOneAndUpdate #model_Model-findOneAndUpdate
|
|
2762
|
-
* @see mongodb https://www.mongodb.
|
|
2762
|
+
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
2763
2763
|
* @api public
|
|
2764
2764
|
*/
|
|
2765
2765
|
|
|
@@ -2799,7 +2799,7 @@ Model.findByIdAndUpdate = function(id, update, options, callback) {
|
|
|
2799
2799
|
* - `findOneAndDelete()`
|
|
2800
2800
|
*
|
|
2801
2801
|
* This function differs slightly from `Model.findOneAndRemove()` in that
|
|
2802
|
-
* `findOneAndRemove()` becomes a [MongoDB `findAndModify()` command](https://
|
|
2802
|
+
* `findOneAndRemove()` becomes a [MongoDB `findAndModify()` command](https://www.mongodb.com/docs/manual/reference/method/db.collection.findAndModify/),
|
|
2803
2803
|
* as opposed to a `findOneAndDelete()` command. For most mongoose use cases,
|
|
2804
2804
|
* this distinction is purely pedantic. You should use `findOneAndDelete()`
|
|
2805
2805
|
* unless you have a good reason not to.
|
|
@@ -2880,7 +2880,7 @@ Model.findOneAndDelete = function(conditions, options, callback) {
|
|
|
2880
2880
|
* @param {Function} [callback]
|
|
2881
2881
|
* @return {Query}
|
|
2882
2882
|
* @see Model.findOneAndRemove #model_Model-findOneAndRemove
|
|
2883
|
-
* @see mongodb https://www.mongodb.
|
|
2883
|
+
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
2884
2884
|
*/
|
|
2885
2885
|
|
|
2886
2886
|
Model.findByIdAndDelete = function(id, options, callback) {
|
|
@@ -3013,7 +3013,7 @@ Model.findOneAndReplace = function(filter, replacement, options, callback) {
|
|
|
3013
3013
|
* @param {Number} [options.maxTimeMS] puts a time limit on the query - requires mongodb >= 2.6.0
|
|
3014
3014
|
* @param {Function} [callback]
|
|
3015
3015
|
* @return {Query}
|
|
3016
|
-
* @see mongodb https://www.mongodb.
|
|
3016
|
+
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
3017
3017
|
* @api public
|
|
3018
3018
|
*/
|
|
3019
3019
|
|
|
@@ -3076,7 +3076,7 @@ Model.findOneAndRemove = function(conditions, options, callback) {
|
|
|
3076
3076
|
* @param {Function} [callback]
|
|
3077
3077
|
* @return {Query}
|
|
3078
3078
|
* @see Model.findOneAndRemove #model_Model-findOneAndRemove
|
|
3079
|
-
* @see mongodb https://www.mongodb.
|
|
3079
|
+
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
3080
3080
|
*/
|
|
3081
3081
|
|
|
3082
3082
|
Model.findByIdAndRemove = function(id, options, callback) {
|
|
@@ -3242,7 +3242,7 @@ Model.create = function create(doc, options, callback) {
|
|
|
3242
3242
|
/**
|
|
3243
3243
|
* _Requires a replica set running MongoDB >= 3.6.0._ Watches the
|
|
3244
3244
|
* underlying collection for changes using
|
|
3245
|
-
* [MongoDB change streams](https://
|
|
3245
|
+
* [MongoDB change streams](https://www.mongodb.com/docs/manual/changeStreams/).
|
|
3246
3246
|
*
|
|
3247
3247
|
* This function does **not** trigger any middleware. In particular, it
|
|
3248
3248
|
* does **not** trigger aggregate middleware.
|
|
@@ -3299,8 +3299,8 @@ Model.watch = function(pipeline, options) {
|
|
|
3299
3299
|
};
|
|
3300
3300
|
|
|
3301
3301
|
/**
|
|
3302
|
-
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://
|
|
3303
|
-
* for benefits like causal consistency, [retryable writes](https://
|
|
3302
|
+
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://www.mongodb.com/docs/manual/release-notes/3.6/#client-sessions)
|
|
3303
|
+
* for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
|
|
3304
3304
|
* and [transactions](https://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
3305
3305
|
*
|
|
3306
3306
|
* Calling `MyModel.startSession()` is equivalent to calling `MyModel.db.startSession()`.
|
|
@@ -3340,7 +3340,7 @@ Model.startSession = function() {
|
|
|
3340
3340
|
* Mongoose always validates each document **before** sending `insertMany`
|
|
3341
3341
|
* to MongoDB. So if one document has a validation error, no documents will
|
|
3342
3342
|
* be saved, unless you set
|
|
3343
|
-
* [the `ordered` option to false](https://
|
|
3343
|
+
* [the `ordered` option to false](https://www.mongodb.com/docs/manual/reference/method/db.collection.insertMany/#error-handling).
|
|
3344
3344
|
*
|
|
3345
3345
|
* This function does **not** trigger save middleware.
|
|
3346
3346
|
*
|
|
@@ -3615,7 +3615,7 @@ function _setIsNew(doc, val) {
|
|
|
3615
3615
|
*
|
|
3616
3616
|
* This function does **not** trigger any middleware, neither `save()`, nor `update()`.
|
|
3617
3617
|
* If you need to trigger
|
|
3618
|
-
* `save()` middleware for every document use [`create()`](
|
|
3618
|
+
* `save()` middleware for every document use [`create()`](#model_Model-create) instead.
|
|
3619
3619
|
*
|
|
3620
3620
|
* #### Example:
|
|
3621
3621
|
*
|
|
@@ -3647,7 +3647,7 @@ function _setIsNew(doc, val) {
|
|
|
3647
3647
|
* console.log(res.insertedCount, res.modifiedCount, res.deletedCount);
|
|
3648
3648
|
* });
|
|
3649
3649
|
*
|
|
3650
|
-
* The [supported operations](https://
|
|
3650
|
+
* The [supported operations](https://www.mongodb.com/docs/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite) are:
|
|
3651
3651
|
*
|
|
3652
3652
|
* - `insertOne`
|
|
3653
3653
|
* - `updateOne`
|
|
@@ -3659,13 +3659,13 @@ function _setIsNew(doc, val) {
|
|
|
3659
3659
|
* @param {Array} ops
|
|
3660
3660
|
* @param {Object} [ops.insertOne.document] The document to insert
|
|
3661
3661
|
* @param {Object} [ops.updateOne.filter] Update the first document that matches this filter
|
|
3662
|
-
* @param {Object} [ops.updateOne.update] An object containing [update operators](https://
|
|
3662
|
+
* @param {Object} [ops.updateOne.update] An object containing [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/)
|
|
3663
3663
|
* @param {Boolean} [ops.updateOne.upsert=false] If true, insert a doc if none match
|
|
3664
3664
|
* @param {Boolean} [ops.updateOne.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to the operation
|
|
3665
3665
|
* @param {Object} [ops.updateOne.collation] The [MongoDB collation](https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-collations) to use
|
|
3666
3666
|
* @param {Array} [ops.updateOne.arrayFilters] The [array filters](https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-36-array-filters.html) used in `update`
|
|
3667
3667
|
* @param {Object} [ops.updateMany.filter] Update all the documents that match this filter
|
|
3668
|
-
* @param {Object} [ops.updateMany.update] An object containing [update operators](https://
|
|
3668
|
+
* @param {Object} [ops.updateMany.update] An object containing [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/)
|
|
3669
3669
|
* @param {Boolean} [ops.updateMany.upsert=false] If true, insert a doc if no documents match `filter`
|
|
3670
3670
|
* @param {Boolean} [ops.updateMany.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to the operation
|
|
3671
3671
|
* @param {Object} [ops.updateMany.collation] The [MongoDB collation](https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-collations) to use
|
|
@@ -3678,11 +3678,11 @@ function _setIsNew(doc, val) {
|
|
|
3678
3678
|
* @param {Object} [options]
|
|
3679
3679
|
* @param {Boolean} [options.ordered=true] If true, execute writes in order and stop at the first error. If false, execute writes in parallel and continue until all writes have either succeeded or errored.
|
|
3680
3680
|
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](/docs/transactions.html).
|
|
3681
|
-
* @param {String|number} [options.w=1] The [write concern](https://
|
|
3682
|
-
* @param {number} [options.wtimeout=null] The [write concern timeout](https://
|
|
3683
|
-
* @param {Boolean} [options.j=true] If false, disable [journal acknowledgement](https://
|
|
3681
|
+
* @param {String|number} [options.w=1] The [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/). See [`Query#w()`](/docs/api/query.html#query_Query-w) for more information.
|
|
3682
|
+
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3683
|
+
* @param {Boolean} [options.j=true] If false, disable [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option)
|
|
3684
3684
|
* @param {Boolean} [options.skipValidation=false] Set to true to skip Mongoose schema validation on bulk write operations. Mongoose currently runs validation on `insertOne` and `replaceOne` operations by default.
|
|
3685
|
-
* @param {Boolean} [options.bypassDocumentValidation=false] If true, disable [MongoDB server-side schema validation](https://
|
|
3685
|
+
* @param {Boolean} [options.bypassDocumentValidation=false] If true, disable [MongoDB server-side schema validation](https://www.mongodb.com/docs/manual/core/schema-validation/) for all writes in this bulk.
|
|
3686
3686
|
* @param {Boolean} [options.strict=null] Overwrites the [`strict` option](/docs/guide.html#strict) on schema. If false, allows filtering and writing fields not defined in the schema for all writes in this bulk.
|
|
3687
3687
|
* @param {Function} [callback] callback `function(error, bulkWriteOpResult) {}`
|
|
3688
3688
|
* @return {Promise} resolves to a [`BulkWriteOpResult`](https://mongodb.github.io/node-mongodb-native/4.9/classes/BulkWriteResult.html) if the operation succeeds
|
|
@@ -3737,9 +3737,9 @@ Model.bulkWrite = function(ops, options, callback) {
|
|
|
3737
3737
|
* @param {Object} [options] options passed to the underlying `bulkWrite()`
|
|
3738
3738
|
* @param {Boolean} [options.timestamps] defaults to `null`, when set to false, mongoose will not add/update timestamps to the documents.
|
|
3739
3739
|
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](/docs/transactions.html).
|
|
3740
|
-
* @param {String|number} [options.w=1] The [write concern](https://
|
|
3741
|
-
* @param {number} [options.wtimeout=null] The [write concern timeout](https://
|
|
3742
|
-
* @param {Boolean} [options.j=true] If false, disable [journal acknowledgement](https://
|
|
3740
|
+
* @param {String|number} [options.w=1] The [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/). See [`Query#w()`](/docs/api/query.html#query_Query-w) for more information.
|
|
3741
|
+
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3742
|
+
* @param {Boolean} [options.j=true] If false, disable [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option)
|
|
3743
3743
|
*
|
|
3744
3744
|
*/
|
|
3745
3745
|
Model.bulkSave = async function(documents, options) {
|
|
@@ -3807,7 +3807,7 @@ function handleSuccessfulWrite(document) {
|
|
|
3807
3807
|
}
|
|
3808
3808
|
|
|
3809
3809
|
document.$__reset();
|
|
3810
|
-
document.schema.s.hooks.execPost('save', document, {}, (err) => {
|
|
3810
|
+
document.schema.s.hooks.execPost('save', document, [document], {}, (err) => {
|
|
3811
3811
|
if (err) {
|
|
3812
3812
|
reject(err);
|
|
3813
3813
|
return;
|
|
@@ -4065,10 +4065,10 @@ Model.hydrate = function(obj, projection, options) {
|
|
|
4065
4065
|
*
|
|
4066
4066
|
* - `strict` (boolean): overrides the [schema-level `strict` option](/docs/guide.html#strict) for this update
|
|
4067
4067
|
* - `upsert` (boolean): whether to create the doc if it doesn't match (false)
|
|
4068
|
-
* - `writeConcern` (object): sets the [write concern](https://
|
|
4068
|
+
* - `writeConcern` (object): 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)
|
|
4069
4069
|
* - `multi` (boolean): whether multiple documents should be updated (false)
|
|
4070
4070
|
* - `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.
|
|
4071
|
-
* - `setDefaultsOnInsert` (boolean): if this 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. This option only works on MongoDB >= 2.4 because it relies on [MongoDB's `$setOnInsert` operator](https://
|
|
4071
|
+
* - `setDefaultsOnInsert` (boolean): if this 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. This option only works on MongoDB >= 2.4 because it relies on [MongoDB's `$setOnInsert` operator](https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/).
|
|
4072
4072
|
* - `timestamps` (boolean): 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.
|
|
4073
4073
|
* - `overwrite` (boolean): disables update-only mode, allowing you to overwrite the doc (false)
|
|
4074
4074
|
*
|
|
@@ -4100,21 +4100,21 @@ Model.hydrate = function(obj, projection, options) {
|
|
|
4100
4100
|
*
|
|
4101
4101
|
* @deprecated
|
|
4102
4102
|
* @see strict https://mongoosejs.com/docs/guide.html#strict
|
|
4103
|
-
* @see response https://
|
|
4103
|
+
* @see response https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#update
|
|
4104
4104
|
* @param {Object} filter
|
|
4105
4105
|
* @param {Object} doc
|
|
4106
4106
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](/docs/api/query.html#query_Query-setOptions)
|
|
4107
4107
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](/docs/guide.html#strict)
|
|
4108
4108
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
4109
|
-
* @param {Object} [options.writeConcern=null] sets the [write concern](https://
|
|
4109
|
+
* @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)
|
|
4110
4110
|
* @param {Boolean} [options.multi=false] whether multiple documents should be updated or just the first one that matches `filter`.
|
|
4111
4111
|
* @param {Boolean} [options.runValidators=false] if true, runs [update validators](/docs/validation.html#update-validators) on this command. Update validators validate the update operation against the model's schema.
|
|
4112
4112
|
* @param {Boolean} [options.setDefaultsOnInsert=false] `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.
|
|
4113
4113
|
* @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.
|
|
4114
|
-
* @param {Boolean} [options.overwrite=false] By default, if you don't include any [update operators](https://
|
|
4114
|
+
* @param {Boolean} [options.overwrite=false] By default, if you don't include any [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/) in `doc`, Mongoose will wrap `doc` in `$set` for you. This prevents you from accidentally overwriting the document. This option tells Mongoose to skip adding `$set`.
|
|
4115
4115
|
* @param {Function} [callback] params are (error, [updateWriteOpResult](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html))
|
|
4116
4116
|
* @return {Query}
|
|
4117
|
-
* @see MongoDB docs https://
|
|
4117
|
+
* @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
|
|
4118
4118
|
* @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
|
|
4119
4119
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
4120
4120
|
* @api public
|
|
@@ -4152,12 +4152,12 @@ Model.update = function update(conditions, doc, options, callback) {
|
|
|
4152
4152
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#query_Query-setOptions)
|
|
4153
4153
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
4154
4154
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
4155
|
-
* @param {Object} [options.writeConcern=null] sets the [write concern](https://
|
|
4155
|
+
* @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)
|
|
4156
4156
|
* @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.
|
|
4157
4157
|
* @param {Function} [callback] `function(error, res) {}` where `res` has 5 properties: `modifiedCount`, `matchedCount`, `acknowledged`, `upsertedId`, and `upsertedCount`.
|
|
4158
4158
|
* @return {Query}
|
|
4159
4159
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
4160
|
-
* @see MongoDB docs https://
|
|
4160
|
+
* @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
|
|
4161
4161
|
* @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
|
|
4162
4162
|
* @api public
|
|
4163
4163
|
*/
|
|
@@ -4193,12 +4193,12 @@ Model.updateMany = function updateMany(conditions, doc, options, callback) {
|
|
|
4193
4193
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#query_Query-setOptions)
|
|
4194
4194
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
4195
4195
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
4196
|
-
* @param {Object} [options.writeConcern=null] sets the [write concern](https://
|
|
4196
|
+
* @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)
|
|
4197
4197
|
* @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.
|
|
4198
4198
|
* @param {Function} [callback] params are (error, writeOpResult)
|
|
4199
4199
|
* @return {Query}
|
|
4200
4200
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
4201
|
-
* @see MongoDB docs https://
|
|
4201
|
+
* @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
|
|
4202
4202
|
* @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
|
|
4203
4203
|
* @api public
|
|
4204
4204
|
*/
|
|
@@ -4231,7 +4231,7 @@ Model.updateOne = function updateOne(conditions, doc, options, callback) {
|
|
|
4231
4231
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#query_Query-setOptions)
|
|
4232
4232
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
4233
4233
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
4234
|
-
* @param {Object} [options.writeConcern=null] sets the [write concern](https://
|
|
4234
|
+
* @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)
|
|
4235
4235
|
* @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.
|
|
4236
4236
|
* @param {Function} [callback] `function(error, res) {}` where `res` has 3 properties: `n`, `nModified`, `ok`.
|
|
4237
4237
|
* @return {Query}
|
|
@@ -4345,7 +4345,7 @@ function _update(model, op, conditions, doc, options, callback) {
|
|
|
4345
4345
|
* @param {String} [opts.out.reduce] add the results to collectionName: if dups are detected, uses the reducer / finalize functions
|
|
4346
4346
|
* @param {String} [opts.out.merge] add the results to collectionName: if dups exist the new docs overwrite the old
|
|
4347
4347
|
* @param {Function} [callback] optional callback
|
|
4348
|
-
* @see MongoDB MapReduce https://www.mongodb.
|
|
4348
|
+
* @see MongoDB MapReduce https://www.mongodb.com/docs/manual/core/map-reduce/
|
|
4349
4349
|
* @return {Promise}
|
|
4350
4350
|
* @api public
|
|
4351
4351
|
*/
|
|
@@ -4398,7 +4398,7 @@ Model.mapReduce = function mapReduce(opts, callback) {
|
|
|
4398
4398
|
};
|
|
4399
4399
|
|
|
4400
4400
|
/**
|
|
4401
|
-
* Performs [aggregations](https://
|
|
4401
|
+
* Performs [aggregations](https://www.mongodb.com/docs/manual/applications/aggregation/) on the models collection.
|
|
4402
4402
|
*
|
|
4403
4403
|
* If a `callback` is passed, the `aggregate` is executed and a `Promise` is returned. If a callback is not passed, the `aggregate` itself is returned.
|
|
4404
4404
|
*
|
|
@@ -4432,10 +4432,10 @@ Model.mapReduce = function mapReduce(opts, callback) {
|
|
|
4432
4432
|
*
|
|
4433
4433
|
* - [Mongoose `Aggregate`](/docs/api/aggregate.html)
|
|
4434
4434
|
* - [An Introduction to Mongoose Aggregate](https://masteringjs.io/tutorials/mongoose/aggregate)
|
|
4435
|
-
* - [MongoDB Aggregation docs](https://
|
|
4435
|
+
* - [MongoDB Aggregation docs](https://www.mongodb.com/docs/manual/applications/aggregation/)
|
|
4436
4436
|
*
|
|
4437
4437
|
* @see Aggregate #aggregate_Aggregate
|
|
4438
|
-
* @see MongoDB https://
|
|
4438
|
+
* @see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
|
|
4439
4439
|
* @param {Array} [pipeline] aggregation pipeline as an array of objects
|
|
4440
4440
|
* @param {Object} [options] aggregation options
|
|
4441
4441
|
* @param {Function} [callback]
|
|
@@ -4641,7 +4641,7 @@ Model.validate = function validate(obj, pathsToValidate, context, callback) {
|
|
|
4641
4641
|
* @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.
|
|
4642
4642
|
* @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).
|
|
4643
4643
|
* @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.
|
|
4644
|
-
* @param {Object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://
|
|
4644
|
+
* @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.
|
|
4645
4645
|
* @param {Boolean} [options.skipInvalidIds=false] By default, Mongoose throws a cast error if `localField` and `foreignField` schemas don't line up. If you enable this option, Mongoose will instead filter out any `localField` properties that cannot be casted to `foreignField`'s schema type.
|
|
4646
4646
|
* @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.
|
|
4647
4647
|
* @param {Boolean} [options.strictPopulate=true] Set to false to allow populating paths that aren't defined in the given model's schema.
|