Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1202

mongosh does not show validation error details in error message

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.0
    • Affects Version/s: 1.3.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      mongosh 1.3.1 w/local mongoDB
    • 2
    • Not Needed
    • Iteration Iguanodon, Iteration Juravenator

      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: [

      { propertyName: 'year', *details: [ [Object] ]* }

      ]
            }
          ]
        }
      }

      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"
                                                                      }
                                                              ]
                                                      }
                                              ]
                                      }
                              ]
                      }
              }

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            enekes.laszlo@qtc-kft.com László Énekes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: