mongoose 9.2.2 → 9.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aggregate.js +41 -41
- package/lib/cast/bigint.js +2 -2
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/double.js +2 -2
- package/lib/cast/int32.js +2 -2
- package/lib/cast/number.js +2 -2
- package/lib/cast/string.js +2 -2
- package/lib/cast.js +6 -6
- package/lib/collection.js +4 -4
- package/lib/connection.js +58 -58
- package/lib/cursor/aggregationCursor.js +6 -6
- package/lib/cursor/queryCursor.js +7 -7
- package/lib/document.js +176 -176
- package/lib/drivers/node-mongodb-native/collection.js +2 -2
- package/lib/drivers/node-mongodb-native/connection.js +8 -8
- package/lib/error/cast.js +2 -2
- package/lib/error/createCollectionsError.js +2 -2
- package/lib/error/divergentArray.js +1 -1
- package/lib/error/eachAsyncMultiError.js +1 -1
- package/lib/error/index.js +2 -2
- package/lib/error/invalidSchemaOption.js +1 -1
- package/lib/error/missingSchema.js +1 -1
- package/lib/error/objectParameter.js +3 -3
- package/lib/error/overwriteModel.js +1 -1
- package/lib/error/setOptionError.js +3 -3
- package/lib/error/strict.js +3 -3
- package/lib/error/strictPopulate.js +2 -2
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +2 -2
- package/lib/error/validator.js +1 -1
- package/lib/error/version.js +2 -2
- package/lib/helpers/buildMiddlewareFilter.js +2 -2
- package/lib/helpers/clone.js +4 -4
- package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
- package/lib/helpers/cursor/eachAsync.js +3 -3
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
- package/lib/helpers/document/applyTimestamps.js +9 -9
- package/lib/helpers/document/applyVirtuals.js +6 -6
- package/lib/helpers/document/compile.js +10 -10
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/lib/helpers/indexes/isIndexEqual.js +3 -3
- package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +2 -2
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +2 -2
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
- package/lib/helpers/populate/assignVals.js +6 -6
- package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
- package/lib/helpers/populate/getSchemaTypes.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/query/castUpdate.js +14 -14
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +4 -4
- package/lib/helpers/query/handleImmutable.js +6 -6
- package/lib/helpers/schema/getIndexes.js +1 -1
- package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +3 -3
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/updateValidators.js +2 -2
- package/lib/model.js +263 -263
- package/lib/mongoose.js +54 -54
- package/lib/options/schemaArrayOptions.js +2 -2
- package/lib/options/schemaBufferOptions.js +1 -1
- package/lib/options/schemaNumberOptions.js +3 -3
- package/lib/options/schemaObjectIdOptions.js +2 -2
- package/lib/options/schemaStringOptions.js +6 -6
- package/lib/options/schemaTypeOptions.js +13 -13
- package/lib/options/virtualOptions.js +11 -11
- package/lib/query.js +222 -222
- package/lib/queryHelpers.js +4 -4
- package/lib/schema/array.js +18 -18
- package/lib/schema/bigint.js +13 -13
- package/lib/schema/boolean.js +13 -13
- package/lib/schema/buffer.js +14 -14
- package/lib/schema/date.js +16 -16
- package/lib/schema/decimal128.js +13 -13
- package/lib/schema/documentArray.js +15 -15
- package/lib/schema/documentArrayElement.js +5 -6
- package/lib/schema/double.js +12 -12
- package/lib/schema/int32.js +13 -13
- package/lib/schema/map.js +10 -10
- package/lib/schema/mixed.js +10 -10
- package/lib/schema/number.js +18 -18
- package/lib/schema/objectId.js +14 -14
- package/lib/schema/operators/text.js +3 -3
- package/lib/schema/string.js +17 -17
- package/lib/schema/subdocument.js +13 -13
- package/lib/schema/union.js +3 -3
- package/lib/schema/uuid.js +16 -16
- package/lib/schema.js +76 -76
- package/lib/schemaType.js +62 -62
- package/lib/stateMachine.js +5 -8
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/arraySubdocument.js +8 -8
- package/lib/types/buffer.js +4 -4
- package/lib/types/documentArray/index.js +1 -1
- package/lib/types/documentArray/methods/index.js +5 -5
- package/lib/types/map.js +3 -3
- package/lib/types/subdocument.js +11 -11
- package/lib/utils.js +45 -45
- package/lib/virtualType.js +18 -18
- package/package.json +8 -5
- package/types/index.d.ts +16 -15
- package/types/inferschematype.d.ts +10 -0
- package/types/models.d.ts +8 -5
- package/types/schemaoptions.d.ts +1 -1
- package/types/virtuals.d.ts +10 -10
package/lib/model.js
CHANGED
|
@@ -109,11 +109,11 @@ const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
|
|
|
109
109
|
* // You also use a model to create queries:
|
|
110
110
|
* const userFromDb = await UserModel.findOne({ name: 'Foo' });
|
|
111
111
|
*
|
|
112
|
-
* @param {
|
|
113
|
-
* @param {
|
|
114
|
-
* @param {
|
|
115
|
-
* @param {
|
|
116
|
-
* @param {
|
|
112
|
+
* @param {object} doc values for initial set
|
|
113
|
+
* @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()).
|
|
114
|
+
* @param {object} [options] optional object containing the options for the document.
|
|
115
|
+
* @param {boolean} [options.defaults=true] if `false`, skip applying default values to this document.
|
|
116
|
+
* @param {boolean} [options.skipId=false] By default, Mongoose document if one is not provided and the document's schema does not override Mongoose's default `_id`. Set `skipId` to `true` to skip this generation step.
|
|
117
117
|
* @inherits Document https://mongoosejs.com/docs/api/document.html
|
|
118
118
|
* @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.
|
|
119
119
|
* @event `index`: Emitted after `Model#ensureIndexes` completes. If an error occurred it is passed with the event.
|
|
@@ -182,8 +182,8 @@ Model.prototype.db;
|
|
|
182
182
|
* If you use `useConnection()` to switch a model's connection, the model will still have the old connection's plugins.
|
|
183
183
|
*
|
|
184
184
|
* @function useConnection
|
|
185
|
-
* @param
|
|
186
|
-
* @return
|
|
185
|
+
* @param {Connection} connection The new connection to use
|
|
186
|
+
* @return {Model} this
|
|
187
187
|
* @api public
|
|
188
188
|
*/
|
|
189
189
|
|
|
@@ -584,20 +584,20 @@ function generateVersionError(doc, modifiedPaths, defaultPaths) {
|
|
|
584
584
|
* const newProduct = await product.save();
|
|
585
585
|
* newProduct === product; // true
|
|
586
586
|
*
|
|
587
|
-
* @param {
|
|
587
|
+
* @param {object} [options] options optional options
|
|
588
588
|
* @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()).
|
|
589
|
-
* @param {
|
|
590
|
-
* @param {
|
|
591
|
-
* @param {
|
|
592
|
-
* @param {
|
|
593
|
-
* @param {
|
|
594
|
-
* @param {
|
|
595
|
-
* @param {
|
|
596
|
-
* @param {
|
|
589
|
+
* @param {object} [options.safe] (DEPRECATED) overrides [schema's safe option](https://mongoosejs.com/docs/guide.html#safe). Use the `w` option instead.
|
|
590
|
+
* @param {boolean} [options.validateBeforeSave] set to false to save without validating.
|
|
591
|
+
* @param {boolean} [options.validateModifiedOnly=false] if `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
|
|
592
|
+
* @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)
|
|
593
|
+
* @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)
|
|
594
|
+
* @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).
|
|
595
|
+
* @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)
|
|
596
|
+
* @param {boolean} [options.timestamps=true] if `false` and [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
|
|
597
597
|
* @param {Array} [options.pathsToSave] An array of paths that tell mongoose to only validate and save the paths in `pathsToSave`.
|
|
598
|
-
* @param {
|
|
599
|
-
* @param {
|
|
600
|
-
* @param {
|
|
598
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
599
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
600
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
601
601
|
* @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).
|
|
602
602
|
* @return {Promise}
|
|
603
603
|
* @api public
|
|
@@ -847,7 +847,7 @@ Model.prototype.deleteOne = function deleteOne(options) {
|
|
|
847
847
|
* doc.$model() === Tank; // true
|
|
848
848
|
* await doc.$model('User').findById(id);
|
|
849
849
|
*
|
|
850
|
-
* @param {
|
|
850
|
+
* @param {string} [name] model name
|
|
851
851
|
* @method $model
|
|
852
852
|
* @api public
|
|
853
853
|
* @return {Model}
|
|
@@ -870,7 +870,7 @@ Model.prototype.$model = function $model(name) {
|
|
|
870
870
|
* doc.$model() === Tank; // true
|
|
871
871
|
* await doc.$model('User').findById(id);
|
|
872
872
|
*
|
|
873
|
-
* @param {
|
|
873
|
+
* @param {string} [name] model name
|
|
874
874
|
* @method model
|
|
875
875
|
* @api public
|
|
876
876
|
* @return {Model}
|
|
@@ -897,8 +897,8 @@ Model.prototype.model = Model.prototype.$model;
|
|
|
897
897
|
*
|
|
898
898
|
* - `findOne()`
|
|
899
899
|
*
|
|
900
|
-
* @param {
|
|
901
|
-
* @param {
|
|
900
|
+
* @param {object} filter
|
|
901
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
902
902
|
* @return {Query}
|
|
903
903
|
*/
|
|
904
904
|
|
|
@@ -942,14 +942,14 @@ Model.exists = function exists(filter, options) {
|
|
|
942
942
|
* const Employee = Person.discriminator('Employee', employeeSchema, 'staff');
|
|
943
943
|
* new Employee().__t; // "staff" because of 3rd argument above
|
|
944
944
|
*
|
|
945
|
-
* @param {
|
|
945
|
+
* @param {string} name discriminator model name
|
|
946
946
|
* @param {Schema} schema discriminator model schema
|
|
947
|
-
* @param {
|
|
948
|
-
* @param {
|
|
949
|
-
* @param {
|
|
950
|
-
* @param {
|
|
951
|
-
* @param {
|
|
952
|
-
* @param {
|
|
947
|
+
* @param {object|string} [options] If string, same as `options.value`.
|
|
948
|
+
* @param {string} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
|
|
949
|
+
* @param {boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
|
|
950
|
+
* @param {boolean} [options.overwriteModels=false] by default, Mongoose does not allow you to define a discriminator with the same name as another discriminator. Set this to allow overwriting discriminators with the same name.
|
|
951
|
+
* @param {boolean} [options.mergeHooks=true] By default, Mongoose merges the base schema's hooks with the discriminator schema's hooks. Set this option to `false` to make Mongoose use the discriminator schema's hooks instead.
|
|
952
|
+
* @param {boolean} [options.mergePlugins=true] By default, Mongoose merges the base schema's plugins with the discriminator schema's plugins. Set this option to `false` to make Mongoose use the discriminator schema's plugins instead.
|
|
953
953
|
* @return {Model} The newly created discriminator model
|
|
954
954
|
* @api public
|
|
955
955
|
*/
|
|
@@ -1172,7 +1172,7 @@ Model.init = function init() {
|
|
|
1172
1172
|
* });
|
|
1173
1173
|
*
|
|
1174
1174
|
* @api public
|
|
1175
|
-
* @param {
|
|
1175
|
+
* @param {object} [options] see [MongoDB driver docs](https://mongodb.github.io/node-mongodb-native/4.9/classes/Db.html#createCollection)
|
|
1176
1176
|
* @returns {Promise}
|
|
1177
1177
|
*/
|
|
1178
1178
|
|
|
@@ -1278,8 +1278,8 @@ Model.createCollection = async function createCollection(options) {
|
|
|
1278
1278
|
* toDrop; // Array of strings containing names of indexes that `syncIndexes()` will drop
|
|
1279
1279
|
* toCreate; // Array of strings containing names of indexes that `syncIndexes()` will create
|
|
1280
1280
|
*
|
|
1281
|
-
* @param {
|
|
1282
|
-
* @param {
|
|
1281
|
+
* @param {object} [options] options to pass to `ensureIndexes()`
|
|
1282
|
+
* @param {boolean} [options.hideIndexes=false] set to `true` to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher
|
|
1283
1283
|
* @return {Promise}
|
|
1284
1284
|
* @api public
|
|
1285
1285
|
*/
|
|
@@ -1323,9 +1323,9 @@ Model.syncIndexes = async function syncIndexes(options) {
|
|
|
1323
1323
|
* const Customer = mongoose.model('Customer', schema);
|
|
1324
1324
|
* await Customer.createSearchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
|
|
1325
1325
|
*
|
|
1326
|
-
* @param {
|
|
1327
|
-
* @param {
|
|
1328
|
-
* @param {
|
|
1326
|
+
* @param {object} description index options, including `name` and `definition`
|
|
1327
|
+
* @param {string} description.name
|
|
1328
|
+
* @param {object} description.definition
|
|
1329
1329
|
* @return {Promise}
|
|
1330
1330
|
* @api public
|
|
1331
1331
|
*/
|
|
@@ -1346,8 +1346,8 @@ Model.createSearchIndex = async function createSearchIndex(description) {
|
|
|
1346
1346
|
* const Customer = mongoose.model('Customer', schema);
|
|
1347
1347
|
* await Customer.updateSearchIndex('test', { mappings: { dynamic: true } });
|
|
1348
1348
|
*
|
|
1349
|
-
* @param {
|
|
1350
|
-
* @param {
|
|
1349
|
+
* @param {string} name
|
|
1350
|
+
* @param {object} definition
|
|
1351
1351
|
* @return {Promise}
|
|
1352
1352
|
* @api public
|
|
1353
1353
|
*/
|
|
@@ -1368,7 +1368,7 @@ Model.updateSearchIndex = async function updateSearchIndex(name, definition) {
|
|
|
1368
1368
|
* const Customer = mongoose.model('Customer', schema);
|
|
1369
1369
|
* await Customer.dropSearchIndex('test');
|
|
1370
1370
|
*
|
|
1371
|
-
* @param {
|
|
1371
|
+
* @param {string} name
|
|
1372
1372
|
* @return {Promise}
|
|
1373
1373
|
* @api public
|
|
1374
1374
|
*/
|
|
@@ -1391,7 +1391,7 @@ Model.dropSearchIndex = async function dropSearchIndex(name) {
|
|
|
1391
1391
|
* await Customer.createSearchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
|
|
1392
1392
|
* const res = await Customer.listSearchIndexes(); // Includes `[{ name: 'test' }]`
|
|
1393
1393
|
*
|
|
1394
|
-
* @param {
|
|
1394
|
+
* @param {object} [options]
|
|
1395
1395
|
* @return {Promise<Array>}
|
|
1396
1396
|
* @api public
|
|
1397
1397
|
*/
|
|
@@ -1413,9 +1413,9 @@ Model.listSearchIndexes = async function listSearchIndexes(options) {
|
|
|
1413
1413
|
* toDrop; // Array of strings containing names of indexes that `syncIndexes()` will drop
|
|
1414
1414
|
* toCreate; // Array of index specs containing the keys of indexes that `syncIndexes()` will create
|
|
1415
1415
|
*
|
|
1416
|
-
* @param {
|
|
1417
|
-
* @param {
|
|
1418
|
-
* @return {Promise<
|
|
1416
|
+
* @param {object} [options]
|
|
1417
|
+
* @param {boolean} [options.indexOptionsToCreate=false] If true, `toCreate` will include both the index spec and the index options, not just the index spec
|
|
1418
|
+
* @return {Promise<object>} contains the indexes that would be dropped in MongoDB and indexes that would be created in MongoDB as `{ toDrop: string[], toCreate: string[] }`.
|
|
1419
1419
|
*/
|
|
1420
1420
|
|
|
1421
1421
|
Model.diffIndexes = async function diffIndexes(options) {
|
|
@@ -1518,10 +1518,10 @@ function getIndexesToDrop(schema, schemaIndexes, dbIndexes) {
|
|
|
1518
1518
|
*
|
|
1519
1519
|
* The returned promise resolves to a list of the dropped indexes' names as an array
|
|
1520
1520
|
*
|
|
1521
|
-
* @param {
|
|
1522
|
-
* @param {
|
|
1523
|
-
* @param {
|
|
1524
|
-
* @return {Promise<
|
|
1521
|
+
* @param {object} [options]
|
|
1522
|
+
* @param {string[]} [options.toDrop] if specified, contains a list of index names to drop
|
|
1523
|
+
* @param {boolean} [options.hideIndexes=false] set to `true` to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher
|
|
1524
|
+
* @return {Promise<string[]>} list of dropped or hidden index names
|
|
1525
1525
|
* @api public
|
|
1526
1526
|
*/
|
|
1527
1527
|
|
|
@@ -1607,7 +1607,7 @@ Model.listIndexes = async function listIndexes() {
|
|
|
1607
1607
|
*
|
|
1608
1608
|
* _NOTE: It is not recommended that you run this in production. Index creation may impact database performance depending on your load. Use with caution._
|
|
1609
1609
|
*
|
|
1610
|
-
* @param {
|
|
1610
|
+
* @param {object} [options] internal options
|
|
1611
1611
|
* @return {Promise}
|
|
1612
1612
|
* @api public
|
|
1613
1613
|
*/
|
|
@@ -1632,7 +1632,7 @@ Model.ensureIndexes = async function ensureIndexes(options) {
|
|
|
1632
1632
|
* Similar to `ensureIndexes()`, except for it uses the [`createIndex`](https://mongodb.github.io/node-mongodb-native/4.9/classes/Db.html#createIndex)
|
|
1633
1633
|
* function.
|
|
1634
1634
|
*
|
|
1635
|
-
* @param {
|
|
1635
|
+
* @param {object} [options] internal options
|
|
1636
1636
|
* @return {Promise}
|
|
1637
1637
|
* @api public
|
|
1638
1638
|
*/
|
|
@@ -1896,9 +1896,9 @@ Model.discriminators;
|
|
|
1896
1896
|
*
|
|
1897
1897
|
* Only translate arguments of object type anything else is returned raw
|
|
1898
1898
|
*
|
|
1899
|
-
* @param {
|
|
1900
|
-
* @param {
|
|
1901
|
-
* @return {
|
|
1899
|
+
* @param {object} fields fields/conditions that may contain aliased keys
|
|
1900
|
+
* @param {boolean} [errorOnDuplicates] if true, throw an error if there's both a key and an alias for that key in `fields`
|
|
1901
|
+
* @return {object} the translated 'pure' fields/conditions
|
|
1902
1902
|
*/
|
|
1903
1903
|
Model.translateAliases = function translateAliases(fields, errorOnDuplicates) {
|
|
1904
1904
|
_checkContext(this, 'translateAliases');
|
|
@@ -1994,9 +1994,9 @@ Model.translateAliases = function translateAliases(fields, errorOnDuplicates) {
|
|
|
1994
1994
|
* This function triggers `deleteOne` query hooks. Read the
|
|
1995
1995
|
* [middleware docs](https://mongoosejs.com/docs/middleware.html#naming) to learn more.
|
|
1996
1996
|
*
|
|
1997
|
-
* @param {
|
|
1998
|
-
* @param {
|
|
1999
|
-
* @param {
|
|
1997
|
+
* @param {object} conditions
|
|
1998
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
1999
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2000
2000
|
* @return {Query}
|
|
2001
2001
|
* @api public
|
|
2002
2002
|
*/
|
|
@@ -2027,9 +2027,9 @@ Model.deleteOne = function deleteOne(conditions, options) {
|
|
|
2027
2027
|
* This function triggers `deleteMany` query hooks. Read the
|
|
2028
2028
|
* [middleware docs](https://mongoosejs.com/docs/middleware.html#naming) to learn more.
|
|
2029
2029
|
*
|
|
2030
|
-
* @param {
|
|
2031
|
-
* @param {
|
|
2032
|
-
* @param {
|
|
2030
|
+
* @param {object} conditions
|
|
2031
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2032
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2033
2033
|
* @return {Query}
|
|
2034
2034
|
* @api public
|
|
2035
2035
|
*/
|
|
@@ -2068,10 +2068,10 @@ Model.deleteMany = function deleteMany(conditions, options) {
|
|
|
2068
2068
|
* // passing options
|
|
2069
2069
|
* await MyModel.find({ name: /john/i }, null, { skip: 10 }).exec();
|
|
2070
2070
|
*
|
|
2071
|
-
* @param {
|
|
2072
|
-
* @param {
|
|
2073
|
-
* @param {
|
|
2074
|
-
* @param {
|
|
2071
|
+
* @param {object|ObjectId} filter
|
|
2072
|
+
* @param {object|string|string[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2073
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2074
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2075
2075
|
* @return {Query}
|
|
2076
2076
|
* @see field selection https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
|
|
2077
2077
|
* @see query casting https://mongoosejs.com/docs/tutorials/query_casting.html
|
|
@@ -2108,9 +2108,9 @@ Model.find = function find(conditions, projection, options) {
|
|
|
2108
2108
|
* // select only the adventures name and length
|
|
2109
2109
|
* await Adventure.findById(id, 'name length').exec();
|
|
2110
2110
|
*
|
|
2111
|
-
* @param {
|
|
2112
|
-
* @param {
|
|
2113
|
-
* @param {
|
|
2111
|
+
* @param {any} id value of `_id` to query by
|
|
2112
|
+
* @param {object|string|string[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2113
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2114
2114
|
* @return {Query}
|
|
2115
2115
|
* @see field selection https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
|
|
2116
2116
|
* @see lean queries https://mongoosejs.com/docs/tutorials/lean.html
|
|
@@ -2146,10 +2146,10 @@ Model.findById = function findById(id, projection, options) {
|
|
|
2146
2146
|
* // Select only the adventures name and length
|
|
2147
2147
|
* await Adventure.findOne({ country: 'Croatia' }, 'name length').exec();
|
|
2148
2148
|
*
|
|
2149
|
-
* @param {
|
|
2150
|
-
* @param {
|
|
2151
|
-
* @param {
|
|
2152
|
-
* @param {
|
|
2149
|
+
* @param {object} [conditions]
|
|
2150
|
+
* @param {object|string|string[]} [projection] optional fields to return, see [`Query.prototype.select()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.select())
|
|
2151
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2152
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2153
2153
|
* @return {Query}
|
|
2154
2154
|
* @see field selection https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
|
|
2155
2155
|
* @see lean queries https://mongoosejs.com/docs/tutorials/lean.html
|
|
@@ -2179,7 +2179,7 @@ Model.findOne = function findOne(conditions, projection, options) {
|
|
|
2179
2179
|
*
|
|
2180
2180
|
* const numAdventures = await Adventure.estimatedDocumentCount();
|
|
2181
2181
|
*
|
|
2182
|
-
* @param {
|
|
2182
|
+
* @param {object} [options]
|
|
2183
2183
|
* @return {Query}
|
|
2184
2184
|
* @api public
|
|
2185
2185
|
*/
|
|
@@ -2214,7 +2214,7 @@ Model.estimatedDocumentCount = function estimatedDocumentCount(options) {
|
|
|
2214
2214
|
* - `$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)
|
|
2215
2215
|
* - `$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)
|
|
2216
2216
|
*
|
|
2217
|
-
* @param {
|
|
2217
|
+
* @param {object} filter
|
|
2218
2218
|
* @return {Query}
|
|
2219
2219
|
* @api public
|
|
2220
2220
|
*/
|
|
@@ -2242,9 +2242,9 @@ Model.countDocuments = function countDocuments(conditions, options) {
|
|
|
2242
2242
|
* const query = Link.distinct('url');
|
|
2243
2243
|
* query.exec();
|
|
2244
2244
|
*
|
|
2245
|
-
* @param {
|
|
2246
|
-
* @param {
|
|
2247
|
-
* @param {
|
|
2245
|
+
* @param {string} field
|
|
2246
|
+
* @param {object} [conditions] optional
|
|
2247
|
+
* @param {object} [options] optional
|
|
2248
2248
|
* @return {Query}
|
|
2249
2249
|
* @api public
|
|
2250
2250
|
*/
|
|
@@ -2281,8 +2281,8 @@ Model.distinct = function distinct(field, conditions, options) {
|
|
|
2281
2281
|
* .where('name', /^b/i)
|
|
2282
2282
|
* ... etc
|
|
2283
2283
|
*
|
|
2284
|
-
* @param {
|
|
2285
|
-
* @param {
|
|
2284
|
+
* @param {string} path
|
|
2285
|
+
* @param {object} [val] optional value
|
|
2286
2286
|
* @return {Query}
|
|
2287
2287
|
* @api public
|
|
2288
2288
|
*/
|
|
@@ -2302,7 +2302,7 @@ Model.where = function where(path, val) {
|
|
|
2302
2302
|
*
|
|
2303
2303
|
* Blog.$where('this.username.indexOf("val") !== -1').exec(function (err, docs) {});
|
|
2304
2304
|
*
|
|
2305
|
-
* @param {
|
|
2305
|
+
* @param {string|Function} argument is a javascript string or anonymous function
|
|
2306
2306
|
* @method $where
|
|
2307
2307
|
* @memberOf Model
|
|
2308
2308
|
* @return {Query}
|
|
@@ -2357,25 +2357,25 @@ Model.$where = function $where() {
|
|
|
2357
2357
|
* doc.name = 'jason bourne';
|
|
2358
2358
|
* await doc.save();
|
|
2359
2359
|
*
|
|
2360
|
-
* @param {
|
|
2361
|
-
* @param {
|
|
2362
|
-
* @param {
|
|
2360
|
+
* @param {object} [conditions]
|
|
2361
|
+
* @param {object} [update]
|
|
2362
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2363
2363
|
* @param {'before'|'after'} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
|
|
2364
|
-
* @param {
|
|
2364
|
+
* @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).
|
|
2365
2365
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2366
|
-
* @param {
|
|
2367
|
-
* @param {
|
|
2368
|
-
* @param {
|
|
2369
|
-
* @param {
|
|
2370
|
-
* @param {
|
|
2371
|
-
* @param {
|
|
2372
|
-
* @param {
|
|
2373
|
-
* @param {
|
|
2374
|
-
* @param {
|
|
2375
|
-
* @param {
|
|
2376
|
-
* @param {
|
|
2377
|
-
* @param {
|
|
2378
|
-
* @param {
|
|
2366
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2367
|
+
* @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.
|
|
2368
|
+
* @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
2369
|
+
* @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())
|
|
2370
|
+
* @param {boolean} [options.new=false] if true, return the modified document rather than the original
|
|
2371
|
+
* @param {object|string} [options.fields] Field selection. Equivalent to `.select(fields).findOneAndUpdate()`
|
|
2372
|
+
* @param {number} [options.maxTimeMS] puts a time limit on the query - requires mongodb >= 2.6.0
|
|
2373
|
+
* @param {object|string} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2374
|
+
* @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
|
|
2375
|
+
* @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
|
|
2376
|
+
* @param {boolean} [options.includeResultMetadata] if true, returns the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html)
|
|
2377
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2378
|
+
* @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
|
|
2379
2379
|
* @return {Query}
|
|
2380
2380
|
* @see Tutorial https://mongoosejs.com/docs/tutorials/findoneandupdate.html
|
|
2381
2381
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
@@ -2446,23 +2446,23 @@ Model.findOneAndUpdate = function(conditions, update, options) {
|
|
|
2446
2446
|
* doc.name = 'jason bourne';
|
|
2447
2447
|
* await doc.save();
|
|
2448
2448
|
*
|
|
2449
|
-
* @param {
|
|
2450
|
-
* @param {
|
|
2451
|
-
* @param {
|
|
2449
|
+
* @param {object|number|string} id value of `_id` to query by
|
|
2450
|
+
* @param {object} [update]
|
|
2451
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2452
2452
|
* @param {'before'|'after'} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
|
|
2453
|
-
* @param {
|
|
2453
|
+
* @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).
|
|
2454
2454
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2455
|
-
* @param {
|
|
2456
|
-
* @param {
|
|
2457
|
-
* @param {
|
|
2458
|
-
* @param {
|
|
2459
|
-
* @param {
|
|
2460
|
-
* @param {
|
|
2461
|
-
* @param {
|
|
2462
|
-
* @param {
|
|
2463
|
-
* @param {
|
|
2464
|
-
* @param {
|
|
2465
|
-
* @param {
|
|
2455
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2456
|
+
* @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.
|
|
2457
|
+
* @param {object|string} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2458
|
+
* @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
|
|
2459
|
+
* @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
|
|
2460
|
+
* @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
|
|
2461
|
+
* @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
2462
|
+
* @param {boolean} [options.new=false] if true, return the modified document rather than the original
|
|
2463
|
+
* @param {object|string} [options.select] sets the document fields to return.
|
|
2464
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2465
|
+
* @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
|
|
2466
2466
|
* @return {Query}
|
|
2467
2467
|
* @see Model.findOneAndUpdate https://mongoosejs.com/docs/api/model.html#Model.findOneAndUpdate()
|
|
2468
2468
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
@@ -2508,16 +2508,16 @@ Model.findByIdAndUpdate = function(id, update, options) {
|
|
|
2508
2508
|
* doc.name = 'jason bourne';
|
|
2509
2509
|
* await doc.save();
|
|
2510
2510
|
*
|
|
2511
|
-
* @param {
|
|
2512
|
-
* @param {
|
|
2513
|
-
* @param {
|
|
2514
|
-
* @param {
|
|
2511
|
+
* @param {object} conditions
|
|
2512
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2513
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2514
|
+
* @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())
|
|
2515
2515
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2516
|
-
* @param {
|
|
2517
|
-
* @param {
|
|
2518
|
-
* @param {
|
|
2519
|
-
* @param {
|
|
2520
|
-
* @param {
|
|
2516
|
+
* @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
|
|
2517
|
+
* @param {object|string} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2518
|
+
* @param {object|string} [options.select] sets the document fields to return.
|
|
2519
|
+
* @param {number} [options.maxTimeMS] puts a time limit on the query - requires mongodb >= 2.6.0
|
|
2520
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2521
2521
|
* @return {Query}
|
|
2522
2522
|
* @api public
|
|
2523
2523
|
*/
|
|
@@ -2550,10 +2550,10 @@ Model.findOneAndDelete = function(conditions, options) {
|
|
|
2550
2550
|
*
|
|
2551
2551
|
* - `findOneAndDelete()`
|
|
2552
2552
|
*
|
|
2553
|
-
* @param {
|
|
2554
|
-
* @param {
|
|
2555
|
-
* @param {
|
|
2556
|
-
* @param {
|
|
2553
|
+
* @param {object|number|string} id value of `_id` to query by
|
|
2554
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2555
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2556
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2557
2557
|
* @return {Query}
|
|
2558
2558
|
* @see Model.findOneAndDelete https://mongoosejs.com/docs/api/model.html#Model.findOneAndDelete()
|
|
2559
2559
|
* @see mongodb https://www.mongodb.com/docs/manual/reference/command/findAndModify/
|
|
@@ -2584,20 +2584,20 @@ Model.findByIdAndDelete = function(id, options) {
|
|
|
2584
2584
|
* A.findOneAndReplace(filter, replacement) // returns Query
|
|
2585
2585
|
* A.findOneAndReplace() // returns Query
|
|
2586
2586
|
*
|
|
2587
|
-
* @param {
|
|
2588
|
-
* @param {
|
|
2589
|
-
* @param {
|
|
2587
|
+
* @param {object} filter Replace the first document that matches this filter
|
|
2588
|
+
* @param {object} [replacement] Replace with this document
|
|
2589
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
2590
2590
|
* @param {'before'|'after'} [options.returnDocument='before'] Has two possible values, `'before'` and `'after'`. By default, it will return the document before the update was applied.
|
|
2591
|
-
* @param {
|
|
2591
|
+
* @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).
|
|
2592
2592
|
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
2593
|
-
* @param {
|
|
2594
|
-
* @param {
|
|
2595
|
-
* @param {
|
|
2596
|
-
* @param {
|
|
2597
|
-
* @param {
|
|
2598
|
-
* @param {
|
|
2599
|
-
* @param {
|
|
2600
|
-
* @param {
|
|
2593
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
2594
|
+
* @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.
|
|
2595
|
+
* @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())
|
|
2596
|
+
* @param {object|string} [options.sort] if multiple docs are found by the conditions, sets the sort order to choose which doc to update.
|
|
2597
|
+
* @param {boolean} [options.includeResultMetadata] if true, returns the full [ModifyResult from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/ModifyResult.html) rather than just the document
|
|
2598
|
+
* @param {object|string} [options.select] sets the document fields to return.
|
|
2599
|
+
* @param {number} [options.maxTimeMS] puts a time limit on the query - requires mongodb >= 2.6.0
|
|
2600
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
2601
2601
|
* @return {Query}
|
|
2602
2602
|
* @api public
|
|
2603
2603
|
*/
|
|
@@ -2643,10 +2643,10 @@ Model.findOneAndReplace = function(filter, replacement, options) {
|
|
|
2643
2643
|
* // specify options.
|
|
2644
2644
|
* await Character.create([{ name: 'Jean-Luc Picard' }], { session });
|
|
2645
2645
|
*
|
|
2646
|
-
* @param {Array|
|
|
2647
|
-
* @param {
|
|
2648
|
-
* @param {
|
|
2649
|
-
* @param {
|
|
2646
|
+
* @param {Array|object} docs Documents to insert, as a spread or array
|
|
2647
|
+
* @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.
|
|
2648
|
+
* @param {boolean} [options.ordered] saves the docs in series rather than parallel.
|
|
2649
|
+
* @param {boolean} [options.aggregateErrors] Aggregate Errors instead of throwing the first one that occurs. Default: false
|
|
2650
2650
|
* @return {Promise}
|
|
2651
2651
|
* @api public
|
|
2652
2652
|
*/
|
|
@@ -2815,8 +2815,8 @@ Model.create = async function create(doc, options) {
|
|
|
2815
2815
|
* // Create a new character within a transaction.
|
|
2816
2816
|
* await Character.insertOne({ name: 'Jean-Luc Picard' }, { session });
|
|
2817
2817
|
*
|
|
2818
|
-
* @param {
|
|
2819
|
-
* @param {
|
|
2818
|
+
* @param {object|Document} doc Document to insert, as a POJO or Mongoose document
|
|
2819
|
+
* @param {object} [options] Options passed down to `save()`.
|
|
2820
2820
|
* @return {Promise<Document>} resolves to the saved document
|
|
2821
2821
|
* @api public
|
|
2822
2822
|
*/
|
|
@@ -2867,8 +2867,8 @@ Model.insertOne = async function insertOne(doc, options) {
|
|
|
2867
2867
|
* await doc.deleteOne();
|
|
2868
2868
|
*
|
|
2869
2869
|
* @param {Array} [pipeline]
|
|
2870
|
-
* @param {
|
|
2871
|
-
* @param {
|
|
2870
|
+
* @param {object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#watch)
|
|
2871
|
+
* @param {boolean} [options.hydrate=false] if true and `fullDocument: 'updateLookup'` is set, Mongoose will automatically hydrate `fullDocument` into a fully fledged Mongoose document
|
|
2872
2872
|
* @return {ChangeStream} mongoose-specific change stream wrapper, inherits from EventEmitter
|
|
2873
2873
|
* @api public
|
|
2874
2874
|
*/
|
|
@@ -2923,8 +2923,8 @@ Model.watch = function(pipeline, options) {
|
|
|
2923
2923
|
* // secondary that is experiencing replication lag.
|
|
2924
2924
|
* doc = await Person.findOne({ name: 'Ned Stark' }, null, { session, readPreference: 'secondary' });
|
|
2925
2925
|
*
|
|
2926
|
-
* @param {
|
|
2927
|
-
* @param {
|
|
2926
|
+
* @param {object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/4.9/classes/MongoClient.html#startSession)
|
|
2927
|
+
* @param {boolean} [options.causalConsistency=true] set to false to disable causal consistency
|
|
2928
2928
|
* @return {Promise<ClientSession>} promise that resolves to a MongoDB driver `ClientSession`
|
|
2929
2929
|
* @api public
|
|
2930
2930
|
*/
|
|
@@ -2966,17 +2966,17 @@ Model.startSession = function() {
|
|
|
2966
2966
|
* { name: 'The Empire Strikes Back' }
|
|
2967
2967
|
* ], { rawResult: true });
|
|
2968
2968
|
*
|
|
2969
|
-
* @param {Array|
|
|
2970
|
-
* @param {
|
|
2971
|
-
* @param {
|
|
2972
|
-
* @param {
|
|
2973
|
-
* @param {
|
|
2974
|
-
* @param {
|
|
2975
|
-
* @param {
|
|
2976
|
-
* @param {
|
|
2977
|
-
* @param {
|
|
2978
|
-
* @param {
|
|
2979
|
-
* @param {
|
|
2969
|
+
* @param {Array|object|any} doc(s)
|
|
2970
|
+
* @param {object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#insertMany)
|
|
2971
|
+
* @param {boolean} [options.ordered=true] if true, will fail fast on the first error encountered. If false, will insert all the documents it can and report errors later. An `insertMany()` with `ordered = false` is called an "unordered" `insertMany()`.
|
|
2972
|
+
* @param {boolean} [options.rawResult=false] if false, the returned promise resolves to the documents that passed mongoose document validation. If `true`, will return the [raw result from the MongoDB driver](https://mongodb.github.io/node-mongodb-native/4.9/interfaces/InsertManyResult.html) with a `mongoose` property that contains `validationErrors` and `results` if this is an unordered `insertMany`.
|
|
2973
|
+
* @param {boolean} [options.lean=false] if `true`, skips hydrating the documents. This means Mongoose will **not** cast, validate, or apply defaults to any of the documents passed to `insertMany()`. This option is useful if you need the extra performance, but comes with data integrity risk. Consider using with [`castObject()`](https://mongoosejs.com/docs/api/model.html#Model.castObject()) and [`applyDefaults()`](https://mongoosejs.com/docs/api/model.html#Model.applyDefaults()).
|
|
2974
|
+
* @param {number} [options.limit=null] this limits the number of documents being processed (validation/casting) by mongoose in parallel, this does **NOT** send the documents in batches to MongoDB. Use this option if you're processing a large number of documents and your app is running out of memory.
|
|
2975
|
+
* @param {string|object|Array} [options.populate=null] populates the result documents. This option is a no-op if `rawResult` is set.
|
|
2976
|
+
* @param {boolean} [options.throwOnValidationError=false] If true and `ordered: false`, throw an error if one of the operations failed validation, but all valid operations completed successfully.
|
|
2977
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
2978
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
2979
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
2980
2980
|
* @return {Promise} resolving to the raw result from the MongoDB driver if `options.rawResult` was `true`, or the documents that passed validation, otherwise
|
|
2981
2981
|
* @api public
|
|
2982
2982
|
*/
|
|
@@ -3304,42 +3304,42 @@ function _setIsNew(doc, val) {
|
|
|
3304
3304
|
* - `replaceOne`
|
|
3305
3305
|
*
|
|
3306
3306
|
* @param {Array} ops
|
|
3307
|
-
* @param {
|
|
3308
|
-
* @param {
|
|
3309
|
-
* @param {
|
|
3310
|
-
* @param {
|
|
3311
|
-
* @param {
|
|
3312
|
-
* @param {
|
|
3313
|
-
* @param {
|
|
3314
|
-
* @param {
|
|
3307
|
+
* @param {object} [ops.insertOne.document] The document to insert
|
|
3308
|
+
* @param {object} [ops.insertOne.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to the operation
|
|
3309
|
+
* @param {object} [ops.updateOne.filter] Update the first document that matches this filter
|
|
3310
|
+
* @param {object} [ops.updateOne.update] An object containing [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/)
|
|
3311
|
+
* @param {boolean} [ops.updateOne.upsert=false] If true, insert a doc if none match
|
|
3312
|
+
* @param {boolean} [ops.updateOne.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to the operation
|
|
3313
|
+
* @param {boolean} [ops.updateOne.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
|
|
3314
|
+
* @param {object} [ops.updateOne.collation] The [MongoDB collation](https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-collations) to use
|
|
3315
3315
|
* @param {Array} [ops.updateOne.arrayFilters] The [array filters](https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-36-array-filters.html) used in `update`
|
|
3316
|
-
* @param {
|
|
3317
|
-
* @param {
|
|
3318
|
-
* @param {
|
|
3319
|
-
* @param {
|
|
3320
|
-
* @param {
|
|
3321
|
-
* @param {
|
|
3316
|
+
* @param {object} [ops.updateMany.filter] Update all the documents that match this filter
|
|
3317
|
+
* @param {object} [ops.updateMany.update] An object containing [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/)
|
|
3318
|
+
* @param {boolean} [ops.updateMany.upsert=false] If true, insert a doc if no documents match `filter`
|
|
3319
|
+
* @param {boolean} [ops.updateMany.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to the operation
|
|
3320
|
+
* @param {boolean} [ops.updateMany.overwriteImmutable=false] Mongoose removes updated immutable properties from `update` by default (excluding $setOnInsert). Set `overwriteImmutable` to `true` to allow updating immutable properties using other update operators.
|
|
3321
|
+
* @param {object} [ops.updateMany.collation] The [MongoDB collation](https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-collations) to use
|
|
3322
3322
|
* @param {Array} [ops.updateMany.arrayFilters] The [array filters](https://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-36-array-filters.html) used in `update`
|
|
3323
|
-
* @param {
|
|
3324
|
-
* @param {
|
|
3325
|
-
* @param {
|
|
3326
|
-
* @param {
|
|
3327
|
-
* @param {
|
|
3328
|
-
* @param {
|
|
3329
|
-
* @param {
|
|
3330
|
-
* @param {
|
|
3331
|
-
* @param {
|
|
3323
|
+
* @param {object} [ops.deleteOne.filter] Delete the first document that matches this filter
|
|
3324
|
+
* @param {object} [ops.deleteMany.filter] Delete all documents that match this filter
|
|
3325
|
+
* @param {object} [ops.replaceOne.filter] Replace the first document that matches this filter
|
|
3326
|
+
* @param {object} [ops.replaceOne.replacement] The replacement document
|
|
3327
|
+
* @param {boolean} [ops.replaceOne.upsert=false] If true, insert a doc if no documents match `filter`
|
|
3328
|
+
* @param {object} [ops.replaceOne.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to the operation
|
|
3329
|
+
* @param {object} [options]
|
|
3330
|
+
* @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.
|
|
3331
|
+
* @param {boolean} [options.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to any operations. Can be overridden at the operation-level.
|
|
3332
3332
|
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
3333
|
-
* @param {
|
|
3333
|
+
* @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.
|
|
3334
3334
|
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3335
|
-
* @param {
|
|
3336
|
-
* @param {
|
|
3337
|
-
* @param {
|
|
3338
|
-
* @param {
|
|
3339
|
-
* @param {
|
|
3340
|
-
* @param {
|
|
3341
|
-
* @param {
|
|
3342
|
-
* @param {
|
|
3335
|
+
* @param {boolean} [options.j=true] If false, disable [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option)
|
|
3336
|
+
* @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.
|
|
3337
|
+
* @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.
|
|
3338
|
+
* @param {boolean} [options.throwOnValidationError=false] If true and `ordered: false`, throw an error if one of the operations failed validation, but all valid operations completed successfully. Note that Mongoose will still send all valid operations to the MongoDB server.
|
|
3339
|
+
* @param {boolean|"throw"} [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.
|
|
3340
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
3341
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
3342
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
3343
3343
|
* @return {Promise} resolves to a [`BulkWriteOpResult`](https://mongodb.github.io/node-mongodb-native/4.9/classes/BulkWriteResult.html) if the operation succeeds
|
|
3344
3344
|
* @api public
|
|
3345
3345
|
*/
|
|
@@ -3505,17 +3505,17 @@ Model.bulkWrite = async function bulkWrite(ops, options) {
|
|
|
3505
3505
|
*
|
|
3506
3506
|
* Note that `bulkSave()` will **not** throw an error if only some of the `save()` calls succeeded.
|
|
3507
3507
|
*
|
|
3508
|
-
* @param {
|
|
3509
|
-
* @param {
|
|
3510
|
-
* @param {
|
|
3508
|
+
* @param {Document[]} documents
|
|
3509
|
+
* @param {object} [options] options passed to the underlying `bulkWrite()`
|
|
3510
|
+
* @param {boolean} [options.timestamps] defaults to `null`, when set to false, mongoose will not add/update timestamps to the documents.
|
|
3511
3511
|
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
3512
|
-
* @param {
|
|
3512
|
+
* @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.
|
|
3513
3513
|
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3514
|
-
* @param {
|
|
3515
|
-
* @param {
|
|
3516
|
-
* @param {
|
|
3517
|
-
* @param {
|
|
3518
|
-
* @param {
|
|
3514
|
+
* @param {boolean} [options.j=true] If false, disable [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option)
|
|
3515
|
+
* @param {boolean} [options.validateBeforeSave=true] set to `false` to skip Mongoose validation on all documents
|
|
3516
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
3517
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
3518
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
3519
3519
|
* @return {BulkWriteResult} the return value from `bulkWrite()`
|
|
3520
3520
|
*/
|
|
3521
3521
|
Model.bulkSave = async function bulkSave(documents, options) {
|
|
@@ -3601,8 +3601,8 @@ async function handleSuccessfulWrite(document, options) {
|
|
|
3601
3601
|
/**
|
|
3602
3602
|
* Apply defaults to the given document or POJO.
|
|
3603
3603
|
*
|
|
3604
|
-
* @param {
|
|
3605
|
-
* @returns {
|
|
3604
|
+
* @param {object|Document} obj object or document to apply defaults on
|
|
3605
|
+
* @returns {object|Document}
|
|
3606
3606
|
* @api public
|
|
3607
3607
|
*/
|
|
3608
3608
|
|
|
@@ -3639,9 +3639,9 @@ Model.applyDefaults = function applyDefaults(doc) {
|
|
|
3639
3639
|
* obj.name; // 'John'
|
|
3640
3640
|
* obj.upper; // 'JOHN', Mongoose applied the return value of the virtual to the given object
|
|
3641
3641
|
*
|
|
3642
|
-
* @param {
|
|
3643
|
-
* @param {
|
|
3644
|
-
* @returns {
|
|
3642
|
+
* @param {object} obj object or document to apply virtuals on
|
|
3643
|
+
* @param {string[]} [virtualsToApply] optional whitelist of virtuals to apply
|
|
3644
|
+
* @returns {object} obj
|
|
3645
3645
|
* @api public
|
|
3646
3646
|
*/
|
|
3647
3647
|
|
|
@@ -3672,11 +3672,11 @@ Model.applyVirtuals = function applyVirtuals(obj, virtualsToApply) {
|
|
|
3672
3672
|
* obj.createdAt; // 2024-06-01T18:00:00.000Z
|
|
3673
3673
|
* obj.updatedAt; // 2024-06-01T18:00:00.000Z
|
|
3674
3674
|
*
|
|
3675
|
-
* @param {
|
|
3676
|
-
* @param {
|
|
3677
|
-
* @param {
|
|
3675
|
+
* @param {object} obj object or document to apply virtuals on
|
|
3676
|
+
* @param {object} [options]
|
|
3677
|
+
* @param {boolean} [options.isUpdate=false] if true, treat this as an update: just set updatedAt, skip setting createdAt. If false, set both createdAt and updatedAt
|
|
3678
3678
|
* @param {Function} [options.currentTime] if set, Mongoose will call this function to get the current time.
|
|
3679
|
-
* @returns {
|
|
3679
|
+
* @returns {object} obj
|
|
3680
3680
|
* @api public
|
|
3681
3681
|
*/
|
|
3682
3682
|
|
|
@@ -3706,10 +3706,10 @@ Model.applyTimestamps = function applyTimestamps(obj, options) {
|
|
|
3706
3706
|
*
|
|
3707
3707
|
* Test.castObject({ num: 'not a number' }); // Throws a ValidationError
|
|
3708
3708
|
*
|
|
3709
|
-
* @param {
|
|
3710
|
-
* @param {
|
|
3711
|
-
* @param {
|
|
3712
|
-
* @returns {
|
|
3709
|
+
* @param {object} obj object or document to cast
|
|
3710
|
+
* @param {object} options options passed to castObject
|
|
3711
|
+
* @param {boolean} options.ignoreCastErrors If set to `true` will not throw a ValidationError and only return values that were successfully cast.
|
|
3712
|
+
* @returns {object} POJO casted to the model's schema
|
|
3713
3713
|
* @throws {ValidationError} if casting failed for at least one path
|
|
3714
3714
|
* @api public
|
|
3715
3715
|
*/
|
|
@@ -3813,11 +3813,11 @@ Model.castObject = function castObject(obj, options) {
|
|
|
3813
3813
|
/**
|
|
3814
3814
|
* Build bulk write operations for `bulkSave()`.
|
|
3815
3815
|
*
|
|
3816
|
-
* @param {
|
|
3817
|
-
* @param {
|
|
3818
|
-
* @param {
|
|
3819
|
-
* @param {
|
|
3820
|
-
* @return {
|
|
3816
|
+
* @param {Document[]} documents The array of documents to build write operations of
|
|
3817
|
+
* @param {object} options
|
|
3818
|
+
* @param {boolean} options.skipValidation defaults to `false`, when set to true, building the write operations will bypass validating the documents.
|
|
3819
|
+
* @param {boolean} options.timestamps defaults to `null`, when set to false, mongoose will not add/update timestamps to the documents.
|
|
3820
|
+
* @return {Promise[]} Returns a array of all Promises the function executes to be awaited.
|
|
3821
3821
|
* @api private
|
|
3822
3822
|
*/
|
|
3823
3823
|
|
|
@@ -3898,13 +3898,13 @@ Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, op
|
|
|
3898
3898
|
* // hydrate previous data into a Mongoose document
|
|
3899
3899
|
* const mongooseCandy = Candy.hydrate({ _id: '54108337212ffb6d459f854c', type: 'jelly bean' });
|
|
3900
3900
|
*
|
|
3901
|
-
* @param {
|
|
3902
|
-
* @param {
|
|
3903
|
-
* @param {
|
|
3904
|
-
* @param {
|
|
3905
|
-
* @param {
|
|
3906
|
-
* @param {
|
|
3907
|
-
* @param {
|
|
3901
|
+
* @param {object} obj
|
|
3902
|
+
* @param {object|string|string[]} [projection] optional projection containing which fields should be selected for this document
|
|
3903
|
+
* @param {object} [options] optional options
|
|
3904
|
+
* @param {boolean} [options.setters=false] if true, apply schema setters when hydrating
|
|
3905
|
+
* @param {boolean} [options.hydratedPopulatedDocs=false] if true, populates the docs if passing pre-populated data
|
|
3906
|
+
* @param {boolean} [options.virtuals=false] if true, sets any virtuals present on `obj`
|
|
3907
|
+
* @param {boolean|'throw'} [options.strict=false] configure strict mode for the hydrated document. In particular, if strict is false, fields not in the schema won't be stripped out; if strict is 'throw', `hydrate()` will throw an error if there are any fields that are not in the schema. Defaults to true (silently strip out fields not in the schema).
|
|
3908
3908
|
* @return {Document} document instance
|
|
3909
3909
|
* @api public
|
|
3910
3910
|
*/
|
|
@@ -3952,15 +3952,15 @@ Model.hydrate = function(obj, projection, options) {
|
|
|
3952
3952
|
*
|
|
3953
3953
|
* - `updateMany()`
|
|
3954
3954
|
*
|
|
3955
|
-
* @param {
|
|
3956
|
-
* @param {
|
|
3957
|
-
* @param {
|
|
3958
|
-
* @param {
|
|
3959
|
-
* @param {
|
|
3960
|
-
* @param {
|
|
3961
|
-
* @param {
|
|
3962
|
-
* @param {
|
|
3963
|
-
* @param {
|
|
3955
|
+
* @param {object} filter
|
|
3956
|
+
* @param {object|Array} update. If array, this update will be treated as an update pipeline and not casted.
|
|
3957
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
3958
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
3959
|
+
* @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
3960
|
+
* @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)
|
|
3961
|
+
* @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.
|
|
3962
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
3963
|
+
* @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
|
|
3964
3964
|
* @return {Query}
|
|
3965
3965
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
3966
3966
|
* @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
|
|
@@ -4000,15 +4000,15 @@ Model.updateMany = function updateMany(conditions, update, options) {
|
|
|
4000
4000
|
*
|
|
4001
4001
|
* - `updateOne()`
|
|
4002
4002
|
*
|
|
4003
|
-
* @param {
|
|
4004
|
-
* @param {
|
|
4005
|
-
* @param {
|
|
4006
|
-
* @param {
|
|
4007
|
-
* @param {
|
|
4008
|
-
* @param {
|
|
4009
|
-
* @param {
|
|
4010
|
-
* @param {
|
|
4011
|
-
* @param {
|
|
4003
|
+
* @param {object} filter
|
|
4004
|
+
* @param {object|Array} update. If array, this update will be treated as an update pipeline and not casted.
|
|
4005
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
4006
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
4007
|
+
* @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
4008
|
+
* @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)
|
|
4009
|
+
* @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.
|
|
4010
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
4011
|
+
* @param {boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
|
|
4012
4012
|
* @return {Query}
|
|
4013
4013
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
4014
4014
|
* @see MongoDB docs https://www.mongodb.com/docs/manual/reference/command/update/#update-command-output
|
|
@@ -4038,14 +4038,14 @@ Model.updateOne = function updateOne(conditions, doc, options) {
|
|
|
4038
4038
|
*
|
|
4039
4039
|
* - `replaceOne()`
|
|
4040
4040
|
*
|
|
4041
|
-
* @param {
|
|
4042
|
-
* @param {
|
|
4043
|
-
* @param {
|
|
4044
|
-
* @param {
|
|
4045
|
-
* @param {
|
|
4046
|
-
* @param {
|
|
4047
|
-
* @param {
|
|
4048
|
-
* @param {
|
|
4041
|
+
* @param {object} filter
|
|
4042
|
+
* @param {object} doc
|
|
4043
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
4044
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
4045
|
+
* @param {boolean} [options.upsert=false] if true, and no documents found, insert a new document
|
|
4046
|
+
* @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)
|
|
4047
|
+
* @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.
|
|
4048
|
+
* @param {boolean} [options.translateAliases=null] If set to `true`, translates any schema-defined aliases in `filter`, `projection`, `update`, and `distinct`. Throws an error if there are any conflicts where both alias and raw property are defined on the same object.
|
|
4049
4049
|
* @return {Query}
|
|
4050
4050
|
* @see Query docs https://mongoosejs.com/docs/queries.html
|
|
4051
4051
|
* @see UpdateResult https://mongodb.github.io/node-mongodb-native/4.9/interfaces/UpdateResult.html
|
|
@@ -4128,7 +4128,7 @@ function _update(model, op, conditions, doc, options) {
|
|
|
4128
4128
|
* @see Aggregate https://mongoosejs.com/docs/api/aggregate.html#Aggregate()
|
|
4129
4129
|
* @see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
|
|
4130
4130
|
* @param {Array} [pipeline] aggregation pipeline as an array of objects
|
|
4131
|
-
* @param {
|
|
4131
|
+
* @param {object} [options] aggregation options
|
|
4132
4132
|
* @return {Aggregate}
|
|
4133
4133
|
* @api public
|
|
4134
4134
|
*/
|
|
@@ -4167,10 +4167,10 @@ Model.aggregate = function aggregate(pipeline, options) {
|
|
|
4167
4167
|
* Object.keys(err.errors); // ['name']
|
|
4168
4168
|
* }
|
|
4169
4169
|
*
|
|
4170
|
-
* @param {
|
|
4171
|
-
* @param {
|
|
4172
|
-
* @param {
|
|
4173
|
-
* @return {Promise<
|
|
4170
|
+
* @param {object} obj
|
|
4171
|
+
* @param {object|Array|string} pathsOrOptions
|
|
4172
|
+
* @param {object} [context]
|
|
4173
|
+
* @return {Promise<object>} casted and validated copy of `obj` if validation succeeded
|
|
4174
4174
|
* @api public
|
|
4175
4175
|
*/
|
|
4176
4176
|
|
|
@@ -4311,20 +4311,20 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
|
|
|
4311
4311
|
* users[0].dog.breed; // undefined because of `select`
|
|
4312
4312
|
*
|
|
4313
4313
|
* @param {Document|Array} docs Either a single document or array of documents to populate.
|
|
4314
|
-
* @param {
|
|
4314
|
+
* @param {object|string} options Either the paths to populate or an object specifying all parameters
|
|
4315
4315
|
* @param {string} [options.path=null] The path to populate.
|
|
4316
4316
|
* @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).
|
|
4317
4317
|
* @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.
|
|
4318
4318
|
* @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).
|
|
4319
4319
|
* @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.
|
|
4320
|
-
* @param {
|
|
4321
|
-
* @param {
|
|
4322
|
-
* @param {
|
|
4323
|
-
* @param {
|
|
4324
|
-
* @param {
|
|
4320
|
+
* @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.
|
|
4321
|
+
* @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.
|
|
4322
|
+
* @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.
|
|
4323
|
+
* @param {boolean} [options.strictPopulate=true] Set to false to allow populating paths that aren't defined in the given model's schema.
|
|
4324
|
+
* @param {object} [options.options=null] Additional options like `limit` and `lean`.
|
|
4325
4325
|
* @param {Function} [options.transform=null] Function that Mongoose will call on every populated document that allows you to transform the populated document.
|
|
4326
|
-
* @param {
|
|
4327
|
-
* @param {
|
|
4326
|
+
* @param {boolean} [options.forceRepopulate=true] Set to `false` to prevent Mongoose from repopulating paths that are already populated
|
|
4327
|
+
* @param {boolean} [options.ordered=false] Set to `true` to execute any populate queries one at a time, as opposed to in parallel. Set this option to `true` if populating multiple paths or paths with multiple models in transactions.
|
|
4328
4328
|
* @return {Promise}
|
|
4329
4329
|
* @api public
|
|
4330
4330
|
*/
|
|
@@ -4797,9 +4797,9 @@ function _assign(model, vals, mod, assignmentOpts) {
|
|
|
4797
4797
|
/**
|
|
4798
4798
|
* Compiler utility.
|
|
4799
4799
|
*
|
|
4800
|
-
* @param {
|
|
4800
|
+
* @param {string|Function} name model name or class extending Model
|
|
4801
4801
|
* @param {Schema} schema
|
|
4802
|
-
* @param {
|
|
4802
|
+
* @param {string} collectionName
|
|
4803
4803
|
* @param {Connection} connection
|
|
4804
4804
|
* @param {Mongoose} base mongoose instance
|
|
4805
4805
|
* @api private
|
|
@@ -4993,7 +4993,7 @@ function applyQueryMethods(model, methods) {
|
|
|
4993
4993
|
*
|
|
4994
4994
|
* @param {Connection} conn
|
|
4995
4995
|
* @param {Schema} [schema]
|
|
4996
|
-
* @param {
|
|
4996
|
+
* @param {string} [collection]
|
|
4997
4997
|
* @return {Model}
|
|
4998
4998
|
* @api private
|
|
4999
4999
|
* @memberOf Model
|