You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Create a meteor project with a collection that has a unique index on a field.
On the client side, try to insert documents using minimongo with the same value for the unique field.
On the client side you will receive a 500 Error.
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'){thrownewMeteor.Error(409,e.toString());}else{throwe;}}
Best regards,
Sebastian
The text was updated successfully, but these errors were encountered:
Sageyuva
added a commit
to Sageyuva/meteor
that referenced
this issue
May 4, 2024
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).
npm-mongo
version4.0.0
was introduced, MongoError was translated into more specific error (see this PR). Since then,npm-mongo
will not throwMongoError
but some variation (for exampleMongoServerError
)How to reproduce
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 functionCollectionPrototype._defineMutationMethods
(allow-deny.js
):Best regards,
Sebastian
The text was updated successfully, but these errors were encountered: