Problem Statement/Rationale
When a document fails validation, the error message does not show the validator.$jsonSchema.properties.<field>.details field, but it would be helpful, if i saw the description for the validation for the specified field.
Steps to Reproduce
Connect to a localDB on localhost:27017, and create a collection in a db with a validator (described with $jsonSchema), add a rule and a description for a field, and try to insert a document that fails the rule, and check if you see the description you added in the schema.
Expected Results{}
It would be really helpful to be able to see the description of the rule that the insert fails. Something like this (or what MongoDB shell 5.0.7 presents, see Additional notes):
```Uncaught:
MongoServerError: Document failed validation
Additional information: {
failingDocumentId: ObjectId("6268f781fbfcf0c517b8df4c"),
details: {
operatorName: '$jsonSchema',
schemaRulesNotSatisfied: [
{
operatorName: 'properties',
propertiesNotSatisfied: [ { propertyName: 'year', details: {
bsonType: "int",
minimum: 2017,
maximum: 3017,
description: "must be an integer in [ 2017, 3017 ] and is required"
}} ]
}
]
}
}```
Actual Results
The 'details' field shows an [ Object ], but the actual details are not visible.
Uncaught:
MongoServerError: Document failed validation
Additional information: {
failingDocumentId: ObjectId("6268f781fbfcf0c517b8df4c"),
details: {
operatorName: '$jsonSchema',
schemaRulesNotSatisfied: [
{
operatorName: 'properties',
propertiesNotSatisfied: [
]
}
]
}
}
Additional Notes
In the older mongo shell (MongoDB shell 5.0.7) the details are visible:
WriteError({
"index" : 0,
"code" : 121,
"errmsg" : "Document failed validation",
"op" : {
"_id" : ObjectId("6267fca37304a5b36d9038bc"),
"name" : "Laci",
"year" : 2000,
"major" : "English",
"address" : {
"street" : "Muegyetem rkp.",
"city" : "Budapest"
}
},
"errInfo" : {
"failingDocumentId" : ObjectId("6267fca37304a5b36d9038bc"),
"details" : {
"operatorName" : "$jsonSchema",
"schemaRulesNotSatisfied" : [
{
"operatorName" : "properties",
"propertiesNotSatisfied" : [
{
"propertyName" : "year",
"details" : [
{
"operatorName" : "minimum",
"specifiedAs" : {
"minimum" : 2017
},
"reason" : "comparison failed",
"consideredValue" : 2000
},
{
"operatorName" : "bsonType",
"specifiedAs" : {
"bsonType" : "int"
},
"reason" : "type did not match",
"consideredValue" : 2000,
"consideredType" : "double"
}
]
}
]
}
]
}
}