Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
Zelyutin opened this issue Mar 31, 2023 · 1 comment · Fixed by #13367
Closed
2 tasks done

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

Zelyutin opened this issue Mar 31, 2023 · 1 comment · Fixed by #13367
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@Zelyutin
Copy link

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

@vkarpov15 vkarpov15 added this to the 7.0.5 milestone Apr 4, 2023
@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Apr 4, 2023
@vkarpov15 vkarpov15 modified the milestones: 7.0.5, 7.1.1 Apr 17, 2023
@AlexRMU
Copy link

AlexRMU commented Apr 30, 2023

+1

vkarpov15 added a commit that referenced this issue May 2, 2023
@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
3 participants