Skip to content

The $isDeleted is not set automatically as the documentation states. #15858

@djereg

Description

@djereg

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.20.1

Node.js version

24.5.0

MongoDB server version

8.0.3

Typescript version (if applicable)

5.9.3

Description

As the documentation says:

The Model.prototype.deleteOne() method sets $isDeleted if the delete operation succeeded.

But it doesn't. The $isDeleted() method returns false after calling the deleteOne() method and the document has been deleted successfully.

The example given in documentation cannot be run because the product variable cannot be redeclared.

TS2451: Cannot redeclare block-scoped variable product

The deleteOne() method returns DeleteResult not the document itself.

The way I achived the expected result is:

await product.deleteOne();
product.$isDeleted(true);

And after I can check whether the document has been deleted or not.

Steps to Reproduce

Follow the example on the documentation page.

Expected Behavior

The $isDeleted() method returns true after calling deleteOne() on the document and it has been successfully deleted from the database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions