Skip to content

Commit

Permalink
docs(api): add Document#$where to API docs
Browse files Browse the repository at this point in the history
Fix #10583
  • Loading branch information
vkarpov15 committed Aug 23, 2021
1 parent 2871c1b commit 6122f4b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ declare module 'mongoose' {
$set(path: string, val: any, type: any, options?: any): this;
$set(value: any): this;

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

/** If this is a discriminator model, `baseModelName` is the name of the base model. */
Expand Down
22 changes: 22 additions & 0 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,28 @@ Object.defineProperty(Document.prototype, '$locals', {

Document.prototype.isNew;

/**
* Set this property to add additional query filters when Mongoose saves this document and `isNew` is false.
*
* ####Example:
*
* // Make sure `save()` never updates a soft deleted document.
* schema.pre('save', function() {
* this.$where = { isDeleted: false };
* });
*
* @api public
* @property $where
* @memberOf Document
* @instance
*/

Object.defineProperty(Document.prototype, '$where', {
configurable: false,
enumerable: false,
writable: true
});

/**
* The string version of this documents _id.
*
Expand Down

0 comments on commit 6122f4b

Please sign in to comment.