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

Model.deleteMany() and Model.deleteOne() does not return acknowledged #11211

Closed
benghaun opened this issue Jan 11, 2022 · 2 comments
Closed

Model.deleteMany() and Model.deleteOne() does not return acknowledged #11211

benghaun opened this issue Jan 11, 2022 · 2 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@benghaun
Copy link

benghaun commented Jan 11, 2022

Do you want to request a feature or report a bug?
This is a bug - or perhaps just inconsistent documentation, I'm not entirely sure which is it.

What is the current behavior?
When calling Model.deleteMany() (or Model.deleteOne()), the return result is { deletedCount: 1 }, and doesn't have the acknowledged property.

If the current behavior is a bug, please provide the steps to reproduce.
Simply call Model.deleteMany() on any model and observe the result. Sample script below:

const mongoose = require('mongoose');

mongoose.connect('mongodb://127.0.0.1:27017', {});

const TestModel = mongoose.model('Test', {
  test: { type: String },
});

const main = async () => {
  console.log('running main');
  const result = await TestModel.deleteMany({});
  console.log(result); // logs { deletedCount: 0 }
};

main()
  .then(() => {
    process.exit(0);
  })
  .catch(err => console.log(err));

What is the expected behavior?
The v6 migration guide states that the result of deleteMany should have both the acknowledged property and the deletedCount property. This is consistent with the TypeScript definitions, which indicate that the result of the deleteMany operation has both deletedCount and acknowledged.

However, the deleteMany API documentation states that only deletedCount is returned, which is consistent with the implementation.

If the intention is to not include acknowledged, then the migration guide and the TypeScript definitions should be updated. If the intention is to include acknowledged, then the implementation and the API documentation should be updated.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: v14.17.5
Mongoose: v6.1.6
MongoDB: 4.0.22

@benghaun benghaun changed the title Model.deleteMany() does not return acknowledged Model.deleteMany() and Model.deleteOne() does not return acknowledged Jan 11, 2022
@IslandRhythms IslandRhythms added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Jan 11, 2022
@vkarpov15 vkarpov15 added this to the 6.1.9 milestone Jan 15, 2022
@Uzlopak
Copy link
Collaborator

Uzlopak commented Jan 29, 2022

Well I think it is not wrong.

https://docs.mongodb.com/manual/reference/write-concern/#j-option

So you have to specify the j-option to get the acknowledgement.

@vkarpov15 vkarpov15 modified the milestones: 6.2.2, 6.2.4 Feb 16, 2022
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed docs This issue is due to a mistake or omission in the mongoosejs.com documentation labels Feb 27, 2022
@vkarpov15
Copy link
Collaborator

This is a bug caused by leftover code from how we handled delete results in Mongoose 5.x. Fix will be in v6.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

4 participants