You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -3311,6 +3345,7 @@ function prepareDiscriminatorCriteria(query) {
3311
3345
* - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
3312
3346
* - `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.
3313
3347
* - `setDefaultsOnInsert`: `true` by default. If `setDefaultsOnInsert` and `upsert` are true, mongoose will apply the [defaults](https://mongoosejs.com/docs/defaults.html) specified in the model's schema if a new document is created.
3348
+
* - `requireFilter`: bool - if true, throws an error if the filter is empty (`{}`). Defaults to false.
3314
3349
*
3315
3350
* #### Example:
3316
3351
*
@@ -3337,6 +3372,7 @@ function prepareDiscriminatorCriteria(query) {
3337
3372
* @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.
3338
3373
* @param {Boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
3339
3374
* @param {Boolean} [options.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.
3375
+
* @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
@@ -3500,6 +3539,7 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3500
3539
*
3501
3540
* - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
3502
3541
* - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
3542
+
* - `requireFilter`: bool - if true, throws an error if the filter is empty (`{}`). Defaults to false.
3503
3543
*
3504
3544
* #### Example:
3505
3545
*
@@ -3512,6 +3552,7 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3512
3552
* @param {Object} [filter]
3513
3553
* @param {Object} [options]
3514
3554
* @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
3555
+
* @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
3515
3556
* @param {ClientSession} [options.session=null] The session associated with this query. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
3516
3557
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
3517
3558
* @return {Query} this
@@ -3551,6 +3592,9 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
3551
3592
this._applyTranslateAliases();
3552
3593
this._castConditions();
3553
3594
3595
+
// Check for empty/invalid filter with requireFilter option
@@ -3590,6 +3634,7 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
3590
3634
* - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
3591
3635
* - `maxTimeMS`: puts a time limit on the query - requires mongodb >= 2.6.0
3592
3636
* - `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
3637
+
* - `requireFilter`: bool - if true, throws an error if the filter is empty (`{}`). Defaults to false.
3593
3638
*
3594
3639
* #### Example:
3595
3640
*
@@ -3612,6 +3657,7 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
3612
3657
* @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.
3613
3658
* @param {Boolean} [options.returnOriginal=null] An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
3614
3659
* @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.
3660
+
* @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
@@ -4119,6 +4172,7 @@ Query.prototype._replaceOne = async function _replaceOne() {
4119
4172
* @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.
4120
4173
* @param {Boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
4121
4174
* @param {Boolean} [options.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.
4175
+
* @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
* @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.
4194
4248
* @param {Boolean} [options.overwriteDiscriminatorKey=false] Mongoose removes discriminator key updates from `update` by default, set `overwriteDiscriminatorKey` to `true` to allow updating the discriminator key
4195
4249
* @param {Boolean} [options.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.
4250
+
* @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
* @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)
4260
4315
* @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.
4261
4316
* @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.
4317
+
* @param {Boolean} [options.requireFilter=false] If true, throws an error if the filter is empty (`{}`)
0 commit comments