Open devvaneio opened 2 years ago
we could also wrap the extra details in a cause error
Hi, first of thank you for the library. Makes life easier working with the mongo on Deno. I am working on the app, which requires the collection validationSchema. As per the new Mongo DB update, the details of this error are sent through the errorInfo field, which is very helpful. can you please help with entire details. Thank you !
{
"code": 121,
"errmsg": "Document failed validation",
"errInfo": {
"failingDocumentId": ObjectId("5fe0eb9642c10f01eeca66a9"),
"details": {
"operatorName": "$jsonSchema",
"schemaRulesNotSatisfied": [
{
"operatorName": "properties",
"propertiesNotSatisfied": [
{
"propertyName": "price",
"details": [
{
"operatorName": "minimum",
"specifiedAs": {
"minimum": 0
},
"reason": "comparison failed",
"consideredValue": -2
}
]
}
]
}
]
}
}
}
Hi, congrats on the project.
I'm having a hard time trying to get errors from the driver, please take a look:
https://github.com/denodrivers/mongo/blob/d5445a476308a6ded290ded326654aa4c92e5e76/src/collection/collection.ts#L191
Could we replace that by the following:
There's no reason to not upstream the entire error. I tested it by changing the cache file.
Before:
Now:
With that, I can parse the errors and give some hints to solve the problem when the user is trying to save the document with the wrong schema or handle errors accordingly with its error code.
Update: We also need to add the
errInfo
to the class just like the nodejs driver: https://github.com/mongodb/node-mongodb-native/blob/417655ac9d87c1c9ca255dfcc81ca828ffde731a/src/error.ts#L171