Skip to content

Commit 6122f4b

Browse files
committedAug 23, 2021
docs(api): add Document#$where to API docs
Fix #10583
1 parent 2871c1b commit 6122f4b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ declare module 'mongoose' {
574574
$set(path: string, val: any, type: any, options?: any): this;
575575
$set(value: any): this;
576576

577-
/** Additional properties to attach to the query when calling `save()` and `isNew` is false. */
577+
/** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */
578578
$where: Record<string, unknown>;
579579

580580
/** If this is a discriminator model, `baseModelName` is the name of the base model. */

‎lib/document.js

+22
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,28 @@ Object.defineProperty(Document.prototype, '$locals', {
265265

266266
Document.prototype.isNew;
267267

268+
/**
269+
* Set this property to add additional query filters when Mongoose saves this document and `isNew` is false.
270+
*
271+
* ####Example:
272+
*
273+
* // Make sure `save()` never updates a soft deleted document.
274+
* schema.pre('save', function() {
275+
* this.$where = { isDeleted: false };
276+
* });
277+
*
278+
* @api public
279+
* @property $where
280+
* @memberOf Document
281+
* @instance
282+
*/
283+
284+
Object.defineProperty(Document.prototype, '$where', {
285+
configurable: false,
286+
enumerable: false,
287+
writable: true
288+
});
289+
268290
/**
269291
* The string version of this documents _id.
270292
*

0 commit comments

Comments
 (0)
Please sign in to comment.