-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
Milestone
Description
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
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request