Skip to content

Document.deleteOne(...).exec is not a function #13223

@Zelyutin

Description

@Zelyutin

Prerequisites

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

Mongoose version

7.0.3

Node.js version

18.15.0

MongoDB server version

6.0.5

Typescript version (if applicable)

5.0.2

Description

I'm trying to use .deleteOne method on the Document previously found with editor code suggestion.
Interesting thing is that it's not documented in https://mongoosejs.com/docs/api/document.html although it has the signature in document.d.ts.

/** Removes this document from the db. */
deleteOne(options?: QueryOptions): QueryWithHelpers<any, this, TQueryHelpers>;

I've tried to await this Query calling exec() on it as with Document.updateOne() or Model.deleteOne() but the error occured while method itself worked well deleting the document.

const team = await Team.findById(someId).exec();
await team.updateOne({title: 'My new title'}).exec(); // This works
await team.deleteOne().exec(); // team.deleteOne(...).exec is not a function
// await Team.deleteOne({_id: someId}).exec(); // This works

Of course for now i'll use Model method, there's no urgent problem, but the situation itself seemed suspicious to me, so I've reported it.

Steps to Reproduce

const teamSchema = new Schema({
    title: {
        type: String,
        required: true
    }
});
const Team = model('Team', teamSchema);
const team = await Team.create({title: 'Test'});
await team.deleteOne().exec();

Expected Behavior

Deleted document and awaitable Promise received without errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptTypes or Types-test related issue / Pull Request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions