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

Allow-deny package does not parse MongoServerError #13121

Open
tanase-sebastian opened this issue May 2, 2024 · 0 comments · May be fixed by #13124
Open

Allow-deny package does not parse MongoServerError #13121

tanase-sebastian opened this issue May 2, 2024 · 0 comments · May be fixed by #13124

Comments

@tanase-sebastian
Copy link

Hello,

I'm writing about an issue when performing insert/update operations using minimongo. This issue is triggered when the collection has a unique index and the insert/update will fail (could also be triggered in other circumstances that we are not aware of).

  • Description: When npm-mongo version 4.0.0 was introduced, MongoError was translated into more specific error (see this PR). Since then, npm-mongo will not throw MongoError but some variation (for example MongoServerError)
  • Meteor version: I am currently using Meteor 2.8.0 but reading the code of newer versions, the problem will still occur.
  • Last meteor version: Before 2.8.0 we were using 1.6 and the issue was not present
  • Operating system: OSX Ventura
  • The expected behavior: When performing an insert/update using the minimongo, if there are unique index issues, correctly report 409 error with the index name to the client.
  • The actual behavior: The client receives a 500 Error and has no way to know what happened on the server side.

How to reproduce

  1. Create a meteor project with a collection that has a unique index on a field.
  2. On the client side, try to insert documents using minimongo with the same value for the unique field.
  3. On the client side you will receive a 500 Error.
  4. On the server side the error is reported correctly: Exception while invoking method '/test/insert' MongoServerError: E11000 duplicate key error collection: meteor.test index: name_1 dup key: { name: "test" }

I think the issue comes from this catch block in the function CollectionPrototype._defineMutationMethods (allow-deny.js):

} catch (e) {
  if (
    e.name === 'MongoError' ||
    // for old versions of MongoDB (probably not necessary but it's here just in case)
    e.name === 'BulkWriteError' ||
    // for newer versions of MongoDB (https://docs.mongodb.com/drivers/node/current/whats-new/#bulkwriteerror---mongobulkwriteerror)
    e.name === 'MongoBulkWriteError' ||
    e.name === 'MinimongoError'
  ) {
    throw new Meteor.Error(409, e.toString());
  } else {
    throw e;
  }
}

Best regards,
Sebastian

Sageyuva added a commit to Sageyuva/meteor that referenced this issue May 4, 2024
…d for inserting data into a MongoDB collection
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

Successfully merging a pull request may close this issue.

1 participant