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

removeMany throw an error if no items to delete with mongoose v6 #415

Open
francois-spectre opened this issue Sep 21, 2022 · 0 comments
Open

Comments

@francois-spectre
Copy link
Contributor

francois-spectre commented Sep 21, 2022

Mongoose version

6.6.1

Node.js version

16

MongoDB server version

5

Description

In case of a removeMany with a filter query that returns no items, with mongoose v5 I got a success with deletedCount: 0. But with mongoose v6 I get an Error with the message {"acknowledged":true,"deletedCount":0}.

I have investigated and here is the issue:

const res = await beforeQueryHelper(resolveParams);

await beforeQueryHelper(resolveParams) returns:

  • With mongoose v5: { n: 0, ok: 1, deletedCount: 0 }.
  • With mongoose v6: {"acknowledged":true,"deletedCount":0}

Steps to Reproduce

With mongoose V6, do a mutation with a filter that match no items like

await client.mutate({
	variables: {ids: []}, 
	mutation: gql`
		mutation yourEntity($ids: [String]!) {
			removeMany(filter: {
				_operators: {
					_id: { in: $ids }
				}
			}) {
				numAffected
			}
		}
	`
})

Expected Behavior

I expect the same behaviour than with mongoose v5: getting a success response { n: 0, ok: 1, deletedCount: 0 }

They mentioned the change in mongoose v6 in the doc here: https://mongoosejs.com/docs/migrating_to_6.html#mongodb-driver-40

francois-spectre added a commit to francois-spectre/graphql-compose-mongoose that referenced this issue Sep 21, 2022
…f deleteCount equal 0 to keep same behavior between mongoose v5 and v6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant