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.
- package/.eslintrc.js +4 -3
- package/README.md +1 -1
- package/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +13 -13
- package/lib/browser.js +12 -12
- package/lib/cast/bigint.js +31 -0
- package/lib/connection.js +45 -8
- package/lib/cursor/AggregationCursor.js +1 -1
- package/lib/cursor/QueryCursor.js +1 -1
- package/lib/document.js +44 -44
- package/lib/error/createCollectionsError.js +26 -0
- package/lib/error/index.js +13 -13
- package/lib/index.js +40 -40
- package/lib/model.js +102 -95
- package/lib/options/SchemaNumberOptions.js +1 -1
- package/lib/options/SchemaObjectIdOptions.js +1 -1
- package/lib/options/SchemaStringOptions.js +1 -1
- package/lib/options/SchemaTypeOptions.js +1 -1
- package/lib/options/VirtualOptions.js +1 -1
- package/lib/query.js +87 -71
- package/lib/schema/SubdocumentPath.js +1 -1
- package/lib/schema/bigint.js +221 -0
- package/lib/schema/boolean.js +4 -0
- package/lib/schema/date.js +2 -2
- package/lib/schema/documentarray.js +1 -1
- package/lib/schema/index.js +8 -19
- package/lib/schema/number.js +3 -3
- package/lib/schema/string.js +7 -7
- package/lib/schema/uuid.js +10 -8
- package/lib/schema.js +49 -47
- package/lib/schematype.js +17 -16
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/index.js +2 -0
- package/lib/types/uuid.js +13 -0
- package/lib/utils.js +2 -0
- package/lib/virtualtype.js +2 -2
- package/package.json +3 -3
- package/scripts/generateSearch.js +2 -1
- package/scripts/tsc-diagnostics-check.js +1 -1
- package/types/index.d.ts +68 -28
- package/types/inferschematype.d.ts +2 -3
- package/types/middlewares.d.ts +10 -3
- package/types/query.d.ts +2 -1
package/lib/model.js
CHANGED
|
@@ -81,12 +81,12 @@ const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
|
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* A Model is a class that's your primary tool for interacting with MongoDB.
|
|
84
|
-
* An instance of a Model is called a [Document](/docs/api/document.html#Document).
|
|
84
|
+
* An instance of a Model is called a [Document](https://mongoosejs.com/docs/api/document.html#Document).
|
|
85
85
|
*
|
|
86
86
|
* In Mongoose, the term "Model" refers to subclasses of the `mongoose.Model`
|
|
87
87
|
* class. You should not use the `mongoose.Model` class directly. The
|
|
88
|
-
* [`mongoose.model()`](/docs/api/mongoose.html#
|
|
89
|
-
* [`connection.model()`](/docs/api/connection.html#
|
|
88
|
+
* [`mongoose.model()`](https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.model()) and
|
|
89
|
+
* [`connection.model()`](https://mongoosejs.com/docs/api/connection.html#Connection.prototype.model()) functions
|
|
90
90
|
* create subclasses of `mongoose.Model` as shown below.
|
|
91
91
|
*
|
|
92
92
|
* #### Example:
|
|
@@ -102,7 +102,7 @@ const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
|
|
|
102
102
|
* const userFromDb = await UserModel.findOne({ name: 'Foo' });
|
|
103
103
|
*
|
|
104
104
|
* @param {Object} doc values for initial set
|
|
105
|
-
* @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#
|
|
105
|
+
* @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](https://mongoosejs.com/docs/api/query.html#Query.prototype.select()).
|
|
106
106
|
* @param {Boolean} [skipId=false] optional boolean. If true, mongoose doesn't add an `_id` field to the document.
|
|
107
107
|
* @inherits Document https://mongoosejs.com/docs/api/document.html
|
|
108
108
|
* @event `error`: If listening to this event, 'error' is emitted when a document was saved and an `error` occurred. If not listening, the event bubbles to the connection used to create this Model.
|
|
@@ -324,7 +324,6 @@ Model.prototype.$__handleSave = function(options, callback) {
|
|
|
324
324
|
// Make sure we don't treat it as a new object on error,
|
|
325
325
|
// since it already exists
|
|
326
326
|
this.$__.inserting = false;
|
|
327
|
-
|
|
328
327
|
const delta = this.$__delta();
|
|
329
328
|
if (delta) {
|
|
330
329
|
if (delta instanceof MongooseError) {
|
|
@@ -361,7 +360,7 @@ Model.prototype.$__handleSave = function(options, callback) {
|
|
|
361
360
|
where[key] = val;
|
|
362
361
|
}
|
|
363
362
|
}
|
|
364
|
-
this.constructor.
|
|
363
|
+
this.constructor.collection.findOne(where, optionsWithCustomValues)
|
|
365
364
|
.then(documentExists => {
|
|
366
365
|
const matchedCount = !documentExists ? 0 : 1;
|
|
367
366
|
callback(null, { $where: where, matchedCount });
|
|
@@ -460,8 +459,8 @@ function generateVersionError(doc, modifiedPaths) {
|
|
|
460
459
|
}
|
|
461
460
|
|
|
462
461
|
/**
|
|
463
|
-
* Saves this document by inserting a new document into the database if [document.isNew](/docs/api/document.html#
|
|
464
|
-
* or sends an [updateOne](/docs/api/document.html#
|
|
462
|
+
* Saves this document by inserting a new document into the database if [document.isNew](https://mongoosejs.com/docs/api/document.html#Document.prototype.isNew) is `true`,
|
|
463
|
+
* or sends an [updateOne](https://mongoosejs.com/docs/api/document.html#Document.prototype.updateOne()) operation with just the modified paths if `isNew` is `false`.
|
|
465
464
|
*
|
|
466
465
|
* #### Example:
|
|
467
466
|
*
|
|
@@ -477,16 +476,16 @@ function generateVersionError(doc, modifiedPaths) {
|
|
|
477
476
|
* newProduct === product; // true
|
|
478
477
|
*
|
|
479
478
|
* @param {Object} [options] options optional options
|
|
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#
|
|
481
|
-
* @param {Object} [options.safe] (DEPRECATED) overrides [schema's safe option](https://mongoosejs.com
|
|
479
|
+
* @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](https://mongoosejs.com/docs/api/document.html#Document.prototype.session()).
|
|
480
|
+
* @param {Object} [options.safe] (DEPRECATED) overrides [schema's safe option](https://mongoosejs.com/docs/guide.html#safe). Use the `w` option instead.
|
|
482
481
|
* @param {Boolean} [options.validateBeforeSave] set to false to save without validating.
|
|
483
482
|
* @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://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://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names)
|
|
488
|
-
* @param {Boolean} [options.timestamps=true] if `false` and [timestamps](
|
|
489
|
-
* @throws {DocumentNotFoundError} if this [save updates an existing document](api/document.html#
|
|
483
|
+
* @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](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
484
|
+
* @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](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
485
|
+
* @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](https://mongoosejs.com/docs/guide.html#writeConcern).
|
|
486
|
+
* @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://docs.mongodb.com/manual/reference/limits/#mongodb-limit-Restrictions-on-Field-Names)
|
|
487
|
+
* @param {Boolean} [options.timestamps=true] if `false` and [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
|
|
488
|
+
* @throws {DocumentNotFoundError} if this [save updates an existing document](https://mongoosejs.com/docs/api/document.html#Document.prototype.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
489
|
* @return {Promise}
|
|
491
490
|
* @api public
|
|
492
491
|
* @see middleware https://mongoosejs.com/docs/middleware.html
|
|
@@ -1103,7 +1102,7 @@ Model.prototype.$model = function $model(name) {
|
|
|
1103
1102
|
* - `findOne()`
|
|
1104
1103
|
*
|
|
1105
1104
|
* @param {Object} filter
|
|
1106
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
1105
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
1107
1106
|
* @return {Query}
|
|
1108
1107
|
*/
|
|
1109
1108
|
|
|
@@ -1250,8 +1249,8 @@ for (const i in EventEmitter.prototype) {
|
|
|
1250
1249
|
* unless [`autoIndex`](https://mongoosejs.com/docs/guide.html#autoIndex) is turned off.
|
|
1251
1250
|
*
|
|
1252
1251
|
* Mongoose calls this function automatically when a model is created using
|
|
1253
|
-
* [`mongoose.model()`](/docs/api/mongoose.html#
|
|
1254
|
-
* [`connection.model()`](/docs/api/connection.html#
|
|
1252
|
+
* [`mongoose.model()`](https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.model()) or
|
|
1253
|
+
* [`connection.model()`](https://mongoosejs.com/docs/api/connection.html#Connection.prototype.model()), so you
|
|
1255
1254
|
* don't need to call `init()` to trigger index builds.
|
|
1256
1255
|
*
|
|
1257
1256
|
* However, you _may_ need to call `init()` to get back a promise that will resolve when your indexes are finished.
|
|
@@ -1395,14 +1394,22 @@ Model.createCollection = async function createCollection(options) {
|
|
|
1395
1394
|
}
|
|
1396
1395
|
}
|
|
1397
1396
|
|
|
1397
|
+
const clusteredIndex = this &&
|
|
1398
|
+
this.schema &&
|
|
1399
|
+
this.schema.options &&
|
|
1400
|
+
this.schema.options.clusteredIndex;
|
|
1401
|
+
if (clusteredIndex != null) {
|
|
1402
|
+
options = Object.assign({ clusteredIndex: { ...clusteredIndex, unique: true } }, options);
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1398
1405
|
try {
|
|
1399
1406
|
await this.db.createCollection(this.$__collection.collectionName, options);
|
|
1400
1407
|
} catch (err) {
|
|
1408
|
+
|
|
1401
1409
|
if (err != null && (err.name !== 'MongoServerError' || err.code !== 48)) {
|
|
1402
1410
|
throw err;
|
|
1403
1411
|
}
|
|
1404
1412
|
}
|
|
1405
|
-
|
|
1406
1413
|
return this.$__collection;
|
|
1407
1414
|
};
|
|
1408
1415
|
|
|
@@ -1581,7 +1588,7 @@ async function _dropIndexes(toDrop, collection) {
|
|
|
1581
1588
|
/**
|
|
1582
1589
|
* Lists the indexes currently defined in MongoDB. This may or may not be
|
|
1583
1590
|
* the same as the indexes defined in your schema depending on whether you
|
|
1584
|
-
* use the [`autoIndex` option](/docs/guide.html#autoIndex) and if you
|
|
1591
|
+
* use the [`autoIndex` option](https://mongoosejs.com/docs/guide.html#autoIndex) and if you
|
|
1585
1592
|
* build indexes manually.
|
|
1586
1593
|
*
|
|
1587
1594
|
* @return {Promise}
|
|
@@ -1950,10 +1957,10 @@ Model.translateAliases = function translateAliases(fields) {
|
|
|
1950
1957
|
* #### Note:
|
|
1951
1958
|
*
|
|
1952
1959
|
* This function triggers `deleteOne` query hooks. Read the
|
|
1953
|
-
* [middleware docs](/docs/middleware.html#naming) to learn more.
|
|
1960
|
+
* [middleware docs](https://mongoosejs.com/docs/middleware.html#naming) to learn more.
|
|
1954
1961
|
*
|
|
1955
1962
|
* @param {Object} conditions
|
|
1956
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
1963
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
1957
1964
|
* @return {Query}
|
|
1958
1965
|
* @api public
|
|
1959
1966
|
*/
|
|
@@ -1984,10 +1991,10 @@ Model.deleteOne = function deleteOne(conditions, options) {
|
|
|
1984
1991
|
* #### Note:
|
|
1985
1992
|
*
|
|
1986
1993
|
* This function triggers `deleteMany` query hooks. Read the
|
|
1987
|
-
* [middleware docs](/docs/middleware.html#naming) to learn more.
|
|
1994
|
+
* [middleware docs](https://mongoosejs.com/docs/middleware.html#naming) to learn more.
|
|
1988
1995
|
*
|
|
1989
1996
|
* @param {Object} conditions
|
|
1990
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
1997
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
1991
1998
|
* @return {Query}
|
|
1992
1999
|
* @api public
|
|
1993
2000
|
*/
|
|
@@ -2009,7 +2016,7 @@ Model.deleteMany = function deleteMany(conditions, options) {
|
|
|
2009
2016
|
* Finds documents.
|
|
2010
2017
|
*
|
|
2011
2018
|
* Mongoose casts the `filter` to match the model's schema before the command is sent.
|
|
2012
|
-
* See our [query casting tutorial](/docs/tutorials/query_casting.html) for
|
|
2019
|
+
* See our [query casting tutorial](https://mongoosejs.com/docs/tutorials/query_casting.html) for
|
|
2013
2020
|
* more information on how Mongoose casts `filter`.
|
|
2014
2021
|
*
|
|
2015
2022
|
* #### Example:
|
|
@@ -2027,11 +2034,11 @@ Model.deleteMany = function deleteMany(conditions, options) {
|
|
|
2027
2034
|
* await MyModel.find({ name: /john/i }, null, { skip: 10 }).exec();
|
|
2028
2035
|
*
|
|
2029
2036
|
* @param {Object|ObjectId} filter
|
|
2030
|
-
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#
|
|
2031
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2037
|
+
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2038
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2032
2039
|
* @return {Query}
|
|
2033
|
-
* @see field selection #
|
|
2034
|
-
* @see query casting /docs/tutorials/query_casting.html
|
|
2040
|
+
* @see field selection https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
|
|
2041
|
+
* @see query casting https://mongoosejs.com/docs/tutorials/query_casting.html
|
|
2035
2042
|
* @api public
|
|
2036
2043
|
*/
|
|
2037
2044
|
|
|
@@ -2073,11 +2080,11 @@ Model.find = function find(conditions, projection, options) {
|
|
|
2073
2080
|
* await Adventure.findById(id, 'name length').exec();
|
|
2074
2081
|
*
|
|
2075
2082
|
* @param {Any} id value of `_id` to query by
|
|
2076
|
-
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](#
|
|
2077
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2083
|
+
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2084
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2078
2085
|
* @return {Query}
|
|
2079
|
-
* @see field selection #
|
|
2080
|
-
* @see lean queries /docs/tutorials/lean.html
|
|
2086
|
+
* @see field selection https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
|
|
2087
|
+
* @see lean queries https://mongoosejs.com/docs/tutorials/lean.html
|
|
2081
2088
|
* @see findById in Mongoose https://masteringjs.io/tutorials/mongoose/find-by-id
|
|
2082
2089
|
* @api public
|
|
2083
2090
|
*/
|
|
@@ -2115,11 +2122,11 @@ Model.findById = function findById(id, projection, options) {
|
|
|
2115
2122
|
* await Adventure.findOne({ country: 'Croatia' }, 'name length').exec();
|
|
2116
2123
|
*
|
|
2117
2124
|
* @param {Object} [conditions]
|
|
2118
|
-
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](#
|
|
2119
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2125
|
+
* @param {Object|String|String[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2126
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2120
2127
|
* @return {Query}
|
|
2121
|
-
* @see field selection #
|
|
2122
|
-
* @see lean queries /docs/tutorials/lean.html
|
|
2128
|
+
* @see field selection https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
|
|
2129
|
+
* @see lean queries https://mongoosejs.com/docs/tutorials/lean.html
|
|
2123
2130
|
* @api public
|
|
2124
2131
|
*/
|
|
2125
2132
|
|
|
@@ -2169,7 +2176,7 @@ Model.estimatedDocumentCount = function estimatedDocumentCount(options) {
|
|
|
2169
2176
|
* });
|
|
2170
2177
|
*
|
|
2171
2178
|
* If you want to count all documents in a large collection,
|
|
2172
|
-
* use the [`estimatedDocumentCount()` function](#
|
|
2179
|
+
* use the [`estimatedDocumentCount()` function](https://mongoosejs.com/docs/api/model.html#Model.estimatedDocumentCount())
|
|
2173
2180
|
* instead. If you call `countDocuments({})`, MongoDB will always execute
|
|
2174
2181
|
* a full collection scan and **not** use any indexes.
|
|
2175
2182
|
*
|
|
@@ -2205,8 +2212,8 @@ Model.countDocuments = function countDocuments(conditions, options) {
|
|
|
2205
2212
|
* Counts number of documents that match `filter` in a database collection.
|
|
2206
2213
|
*
|
|
2207
2214
|
* This method is deprecated. If you want to count the number of documents in
|
|
2208
|
-
* a collection, e.g. `count({})`, use the [`estimatedDocumentCount()` function](#
|
|
2209
|
-
* instead. Otherwise, use the [`countDocuments()`](#
|
|
2215
|
+
* a collection, e.g. `count({})`, use the [`estimatedDocumentCount()` function](https://mongoosejs.com/docs/api/model.html#Model.estimatedDocumentCount())
|
|
2216
|
+
* instead. Otherwise, use the [`countDocuments()`](https://mongoosejs.com/docs/api/model.html#Model.countDocuments()) function instead.
|
|
2210
2217
|
*
|
|
2211
2218
|
* #### Example:
|
|
2212
2219
|
*
|
|
@@ -2298,7 +2305,7 @@ Model.where = function where(path, val) {
|
|
|
2298
2305
|
* @method $where
|
|
2299
2306
|
* @memberOf Model
|
|
2300
2307
|
* @return {Query}
|
|
2301
|
-
* @see Query.$where #
|
|
2308
|
+
* @see Query.$where https://mongoosejs.com/docs/api/query.html#Query.prototype.$where
|
|
2302
2309
|
* @api public
|
|
2303
2310
|
*/
|
|
2304
2311
|
|
|
@@ -2346,24 +2353,24 @@ Model.$where = function $where() {
|
|
|
2346
2353
|
*
|
|
2347
2354
|
* @param {Object} [conditions]
|
|
2348
2355
|
* @param {Object} [update]
|
|
2349
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2356
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2350
2357
|
* @param {String} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
|
|
2351
|
-
* @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](/docs/api/query.html#
|
|
2352
|
-
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2358
|
+
* @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).
|
|
2359
|
+
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2353
2360
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2354
|
-
* @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.
|
|
2355
|
-
* @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)](#
|
|
2361
|
+
* @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.
|
|
2362
|
+
* @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)](https://mongoosejs.com/docs/api/model.html#Model.findOneAndReplace()).
|
|
2356
2363
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
2357
|
-
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#
|
|
2364
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2358
2365
|
* @param {Boolean} [options.new=false] if true, return the modified document rather than the original
|
|
2359
2366
|
* @param {Object|String} [options.fields] Field selection. Equivalent to `.select(fields).findOneAndUpdate()`
|
|
2360
2367
|
* @param {Number} [options.maxTimeMS] puts a time limit on the query - requires mongodb >= 2.6.0
|
|
2361
2368
|
* @param {Object|String} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2362
|
-
* @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
|
|
2369
|
+
* @param {Boolean} [options.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
|
|
2363
2370
|
* @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
|
|
2364
2371
|
* @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)
|
|
2365
2372
|
* @return {Query}
|
|
2366
|
-
* @see Tutorial /docs/tutorials/findoneandupdate.html
|
|
2373
|
+
* @see Tutorial https://mongoosejs.com/docs/tutorials/findoneandupdate.html
|
|
2367
2374
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
2368
2375
|
* @api public
|
|
2369
2376
|
*/
|
|
@@ -2466,22 +2473,22 @@ function _decorateUpdateWithVersionKey(update, options, versionKey) {
|
|
|
2466
2473
|
*
|
|
2467
2474
|
* @param {Object|Number|String} id value of `_id` to query by
|
|
2468
2475
|
* @param {Object} [update]
|
|
2469
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2476
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2470
2477
|
* @param {String} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
|
|
2471
|
-
* @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](/docs/api/query.html#
|
|
2472
|
-
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2478
|
+
* @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).
|
|
2479
|
+
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2473
2480
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2474
|
-
* @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.
|
|
2475
|
-
* @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)](#
|
|
2481
|
+
* @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.
|
|
2482
|
+
* @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)](https://mongoosejs.com/docs/api/model.html#Model.findOneAndReplace()).
|
|
2476
2483
|
* @param {Object|String} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2477
|
-
* @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
|
|
2484
|
+
* @param {Boolean} [options.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
|
|
2478
2485
|
* @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
|
|
2479
2486
|
* @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)
|
|
2480
2487
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
2481
2488
|
* @param {Boolean} [options.new=false] if true, return the modified document rather than the original
|
|
2482
2489
|
* @param {Object|String} [options.select] sets the document fields to return.
|
|
2483
2490
|
* @return {Query}
|
|
2484
|
-
* @see Model.findOneAndUpdate #
|
|
2491
|
+
* @see Model.findOneAndUpdate https://mongoosejs.com/docs/api/model.html#Model.findOneAndUpdate()
|
|
2485
2492
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
2486
2493
|
* @api public
|
|
2487
2494
|
*/
|
|
@@ -2532,10 +2539,10 @@ Model.findByIdAndUpdate = function(id, update, options) {
|
|
|
2532
2539
|
* await doc.save();
|
|
2533
2540
|
*
|
|
2534
2541
|
* @param {Object} conditions
|
|
2535
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2542
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2536
2543
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2537
|
-
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#
|
|
2538
|
-
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2544
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2545
|
+
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2539
2546
|
* @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)
|
|
2540
2547
|
* @param {Object|String} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2541
2548
|
* @param {Object|String} [options.select] sets the document fields to return.
|
|
@@ -2573,10 +2580,10 @@ Model.findOneAndDelete = function(conditions, options) {
|
|
|
2573
2580
|
* - `findOneAndDelete()`
|
|
2574
2581
|
*
|
|
2575
2582
|
* @param {Object|Number|String} id value of `_id` to query by
|
|
2576
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2583
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2577
2584
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2578
2585
|
* @return {Query}
|
|
2579
|
-
* @see Model.findOneAndRemove #
|
|
2586
|
+
* @see Model.findOneAndRemove https://mongoosejs.com/docs/api/model.html#Model.findOneAndRemove()
|
|
2580
2587
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
2581
2588
|
*/
|
|
2582
2589
|
|
|
@@ -2607,13 +2614,13 @@ Model.findByIdAndDelete = function(id, options) {
|
|
|
2607
2614
|
*
|
|
2608
2615
|
* @param {Object} filter Replace the first document that matches this filter
|
|
2609
2616
|
* @param {Object} [replacement] Replace with this document
|
|
2610
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2617
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2611
2618
|
* @param {String} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
|
|
2612
|
-
* @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](/docs/api/query.html#
|
|
2613
|
-
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2619
|
+
* @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).
|
|
2620
|
+
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2614
2621
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2615
|
-
* @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.
|
|
2616
|
-
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#
|
|
2622
|
+
* @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.
|
|
2623
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2617
2624
|
* @param {Object|String} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2618
2625
|
* @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)
|
|
2619
2626
|
* @param {Object|String} [options.select] sets the document fields to return.
|
|
@@ -2667,10 +2674,10 @@ Model.findOneAndReplace = function(filter, replacement, options) {
|
|
|
2667
2674
|
* await doc.save();
|
|
2668
2675
|
*
|
|
2669
2676
|
* @param {Object} conditions
|
|
2670
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2671
|
-
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2677
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2678
|
+
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2672
2679
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2673
|
-
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#
|
|
2680
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2674
2681
|
* @param {Object|String} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2675
2682
|
* @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)
|
|
2676
2683
|
* @param {Object|String} [options.select] sets the document fields to return.
|
|
@@ -2715,15 +2722,15 @@ Model.findOneAndRemove = function(conditions, options) {
|
|
|
2715
2722
|
* A.findByIdAndRemove() // returns Query
|
|
2716
2723
|
*
|
|
2717
2724
|
* @param {Object|Number|String} id value of `_id` to query by
|
|
2718
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
2725
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2719
2726
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2720
|
-
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](/docs/transactions.html).
|
|
2721
|
-
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](#
|
|
2727
|
+
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2728
|
+
* @param {Object|String|String[]} [options.projection=null] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2722
2729
|
* @param {Object|String} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2723
2730
|
* @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)
|
|
2724
2731
|
* @param {Object|String} [options.select] sets the document fields to return.
|
|
2725
2732
|
* @return {Query}
|
|
2726
|
-
* @see Model.findOneAndRemove #
|
|
2733
|
+
* @see Model.findOneAndRemove https://mongoosejs.com/docs/api/model.html#Model.findOneAndRemove()
|
|
2727
2734
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
2728
2735
|
*/
|
|
2729
2736
|
|
|
@@ -2760,7 +2767,7 @@ Model.findByIdAndRemove = function(id, options) {
|
|
|
2760
2767
|
* await Character.create([{ name: 'Jean-Luc Picard' }], { session });
|
|
2761
2768
|
*
|
|
2762
2769
|
* @param {Array|Object} docs Documents to insert, as a spread or array
|
|
2763
|
-
* @param {Object} [options] Options passed down to `save()`. To specify `options`, `docs` **must** be an array, not a spread. See [Model.save](#
|
|
2770
|
+
* @param {Object} [options] Options passed down to `save()`. To specify `options`, `docs` **must** be an array, not a spread. See [Model.save](https://mongoosejs.com/docs/api/model.html#Model.prototype.save()) for available options.
|
|
2764
2771
|
* @return {Promise}
|
|
2765
2772
|
* @api public
|
|
2766
2773
|
*/
|
|
@@ -2801,7 +2808,7 @@ Model.create = async function create(doc, options) {
|
|
|
2801
2808
|
// to use a spread to specify options, see gh-7535
|
|
2802
2809
|
utils.warn('WARNING: to pass a `session` to `Model.create()` in ' +
|
|
2803
2810
|
'Mongoose, you **must** pass an array as the first argument. See: ' +
|
|
2804
|
-
'https://mongoosejs.com/docs/api/model.html#
|
|
2811
|
+
'https://mongoosejs.com/docs/api/model.html#Model.create()');
|
|
2805
2812
|
}
|
|
2806
2813
|
}
|
|
2807
2814
|
|
|
@@ -3233,7 +3240,7 @@ function _setIsNew(doc, val) {
|
|
|
3233
3240
|
*
|
|
3234
3241
|
* This function does **not** trigger any middleware, neither `save()`, nor `update()`.
|
|
3235
3242
|
* If you need to trigger
|
|
3236
|
-
* `save()` middleware for every document use [`create()`](#
|
|
3243
|
+
* `save()` middleware for every document use [`create()`](https://mongoosejs.com/docs/api/model.html#Model.create()) instead.
|
|
3237
3244
|
*
|
|
3238
3245
|
* #### Example:
|
|
3239
3246
|
*
|
|
@@ -3295,13 +3302,13 @@ function _setIsNew(doc, val) {
|
|
|
3295
3302
|
* @param {Boolean} [ops.replaceOne.upsert=false] If true, insert a doc if no documents match `filter`
|
|
3296
3303
|
* @param {Object} [options]
|
|
3297
3304
|
* @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.
|
|
3298
|
-
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](/docs/transactions.html).
|
|
3299
|
-
* @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#
|
|
3305
|
+
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
3306
|
+
* @param {String|number} [options.w=1] The [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/). See [`Query#w()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.w()) for more information.
|
|
3300
3307
|
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3301
3308
|
* @param {Boolean} [options.j=true] If false, disable [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option)
|
|
3302
3309
|
* @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.
|
|
3303
3310
|
* @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.
|
|
3304
|
-
* @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.
|
|
3311
|
+
* @param {Boolean} [options.strict=null] Overwrites the [`strict` option](https://mongoosejs.com/docs/guide.html#strict) on schema. If false, allows filtering and writing fields not defined in the schema for all writes in this bulk.
|
|
3305
3312
|
* @return {Promise} resolves to a [`BulkWriteOpResult`](https://mongodb.github.io/node-mongodb-native/4.9/classes/BulkWriteResult.html) if the operation succeeds
|
|
3306
3313
|
* @api public
|
|
3307
3314
|
*/
|
|
@@ -3398,8 +3405,8 @@ Model.bulkWrite = async function bulkWrite(ops, options) {
|
|
|
3398
3405
|
* @param {Array<Document>} documents
|
|
3399
3406
|
* @param {Object} [options] options passed to the underlying `bulkWrite()`
|
|
3400
3407
|
* @param {Boolean} [options.timestamps] defaults to `null`, when set to false, mongoose will not add/update timestamps to the documents.
|
|
3401
|
-
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](/docs/transactions.html).
|
|
3402
|
-
* @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#
|
|
3408
|
+
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
3409
|
+
* @param {String|number} [options.w=1] The [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/). See [`Query#w()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.w()) for more information.
|
|
3403
3410
|
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3404
3411
|
* @param {Boolean} [options.j=true] If false, disable [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option)
|
|
3405
3412
|
*
|
|
@@ -3727,11 +3734,11 @@ Model.hydrate = function(obj, projection, options) {
|
|
|
3727
3734
|
*
|
|
3728
3735
|
* @param {Object} filter
|
|
3729
3736
|
* @param {Object|Array} update
|
|
3730
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
3737
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
3731
3738
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
3732
3739
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
3733
|
-
* @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)
|
|
3734
|
-
* @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.
|
|
3740
|
+
* @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)
|
|
3741
|
+
* @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.
|
|
3735
3742
|
* @return {Query}
|
|
3736
3743
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
3737
3744
|
* @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
|
|
@@ -3765,11 +3772,11 @@ Model.updateMany = function updateMany(conditions, doc, options) {
|
|
|
3765
3772
|
*
|
|
3766
3773
|
* @param {Object} filter
|
|
3767
3774
|
* @param {Object|Array} update
|
|
3768
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
3775
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
3769
3776
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
3770
3777
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
3771
|
-
* @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)
|
|
3772
|
-
* @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.
|
|
3778
|
+
* @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)
|
|
3779
|
+
* @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.
|
|
3773
3780
|
* @return {Query}
|
|
3774
3781
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
3775
3782
|
* @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
|
|
@@ -3801,11 +3808,11 @@ Model.updateOne = function updateOne(conditions, doc, options) {
|
|
|
3801
3808
|
*
|
|
3802
3809
|
* @param {Object} filter
|
|
3803
3810
|
* @param {Object} doc
|
|
3804
|
-
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#
|
|
3811
|
+
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
3805
3812
|
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
3806
3813
|
* @param {Boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
3807
|
-
* @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)
|
|
3808
|
-
* @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.
|
|
3814
|
+
* @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)
|
|
3815
|
+
* @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.
|
|
3809
3816
|
* @return {Query}
|
|
3810
3817
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
3811
3818
|
* @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
|
|
@@ -3884,11 +3891,11 @@ function _update(model, op, conditions, doc, options) {
|
|
|
3884
3891
|
*
|
|
3885
3892
|
* #### More About Aggregations:
|
|
3886
3893
|
*
|
|
3887
|
-
* - [Mongoose `Aggregate`](/docs/api/aggregate.html)
|
|
3894
|
+
* - [Mongoose `Aggregate`](https://mongoosejs.com/docs/api/aggregate.html)
|
|
3888
3895
|
* - [An Introduction to Mongoose Aggregate](https://masteringjs.io/tutorials/mongoose/aggregate)
|
|
3889
3896
|
* - [MongoDB Aggregation docs](https://www.mongodb.com/docs/manual/applications/aggregation/)
|
|
3890
3897
|
*
|
|
3891
|
-
* @see Aggregate #
|
|
3898
|
+
* @see Aggregate https://mongoosejs.com/docs/api/aggregate.html#Aggregate()
|
|
3892
3899
|
* @see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
|
|
3893
3900
|
* @param {Array} [pipeline] aggregation pipeline as an array of objects
|
|
3894
3901
|
* @param {Object} [options] aggregation options
|
|
@@ -4079,9 +4086,9 @@ Model.validate = async function validate(obj, pathsToValidate, context) {
|
|
|
4079
4086
|
* @param {Document|Array} docs Either a single document or array of documents to populate.
|
|
4080
4087
|
* @param {Object|String} options Either the paths to populate or an object specifying all parameters
|
|
4081
4088
|
* @param {string} [options.path=null] The path to populate.
|
|
4082
|
-
* @param {string|PopulateOptions} [options.populate=null] Recursively populate paths in the populated documents. See [deep populate docs](/docs/populate.html#deep-populate).
|
|
4089
|
+
* @param {string|PopulateOptions} [options.populate=null] Recursively populate paths in the populated documents. See [deep populate docs](https://mongoosejs.com/docs/populate.html#deep-populate).
|
|
4083
4090
|
* @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.
|
|
4084
|
-
* @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).
|
|
4091
|
+
* @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).
|
|
4085
4092
|
* @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.
|
|
4086
4093
|
* @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.
|
|
4087
4094
|
* @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.
|
|
@@ -69,7 +69,7 @@ Object.defineProperty(SchemaNumberOptions.prototype, 'max', opts);
|
|
|
69
69
|
Object.defineProperty(SchemaNumberOptions.prototype, 'enum', opts);
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
* Sets default [populate options](/docs/populate.html#query-conditions).
|
|
72
|
+
* Sets default [populate options](https://mongoosejs.com/docs/populate.html#query-conditions).
|
|
73
73
|
*
|
|
74
74
|
* #### Example:
|
|
75
75
|
*
|
|
@@ -32,7 +32,7 @@ const opts = require('./propertyOptions');
|
|
|
32
32
|
Object.defineProperty(SchemaObjectIdOptions.prototype, 'auto', opts);
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* Sets default [populate options](/docs/populate.html#query-conditions).
|
|
35
|
+
* Sets default [populate options](https://mongoosejs.com/docs/populate.html#query-conditions).
|
|
36
36
|
*
|
|
37
37
|
* #### Example:
|
|
38
38
|
*
|
|
@@ -120,7 +120,7 @@ Object.defineProperty(SchemaStringOptions.prototype, 'maxLength', opts);
|
|
|
120
120
|
Object.defineProperty(SchemaStringOptions.prototype, 'maxlength', opts);
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
* Sets default [populate options](/docs/populate.html#query-conditions).
|
|
123
|
+
* Sets default [populate options](https://mongoosejs.com/docs/populate.html#query-conditions).
|
|
124
124
|
*
|
|
125
125
|
* @api public
|
|
126
126
|
* @property populate
|
|
@@ -161,7 +161,7 @@ Object.defineProperty(SchemaTypeOptions.prototype, 'index', opts);
|
|
|
161
161
|
/**
|
|
162
162
|
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
|
|
163
163
|
* will build a unique index on this path when the
|
|
164
|
-
* model is compiled. [The `unique` option is **not** a validator](/docs/validation.html#the-unique-option-is-not-a-validator).
|
|
164
|
+
* model is compiled. [The `unique` option is **not** a validator](https://mongoosejs.com/docs/validation.html#the-unique-option-is-not-a-validator).
|
|
165
165
|
*
|
|
166
166
|
* @api public
|
|
167
167
|
* @property unique
|
|
@@ -146,7 +146,7 @@ Object.defineProperty(VirtualOptions.prototype, 'skip', opts);
|
|
|
146
146
|
Object.defineProperty(VirtualOptions.prototype, 'limit', opts);
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
* The `limit` option for `populate()` has [some unfortunate edge cases](/docs/populate.html#query-conditions)
|
|
149
|
+
* The `limit` option for `populate()` has [some unfortunate edge cases](https://mongoosejs.com/docs/populate.html#query-conditions)
|
|
150
150
|
* when working with multiple documents, like `.find().populate()`. The
|
|
151
151
|
* `perDocumentLimit` option makes `populate()` execute a separate query
|
|
152
152
|
* for each document returned from `find()` to ensure each document
|