Skip to content

Difference in pre-middleware arguments between .remove() and .deleteOne() #15870

@unc0ded

Description

@unc0ded

Prerequisites

  • I have written a descriptive issue title

Mongoose version

6.13.8

Node.js version

22.21.1

MongoDB version

8.x

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Issue

I needed some help understanding the difference between the options passed to doc.remove() in Mongoose 6.x vs doc.deleteOne(). From what I know, "remove" worked similar to "save", in that any options passed when calling doc.remove(options) were available in the pre middleware. However, since I have switched to using "deleteOne", and attaching document middleware on it, the options object is no longer available as the second argument in pre middleware. In fact, the document instance itself is the second argument.

I am maintaining some code which used to pass custom options (for example, request identifiers) when deleting the document, that I need to access in the pre/post middleware. Is there no way to access the options object similar to remove/save?

Metadata

Metadata

Assignees

No one assigned

    Labels

    helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessaryhelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions