What is the status on improved json schema error messages?

Hey all,

just stumbled onto this article: Improved Error Messages for Schema Validation in MongoDB 5.0.

…that basically promises improved error messages when jsonSchema validation fails in Mongo 5.?.

This sounds really awesome and we can’t wait for this to be improved :nerd_face:

Tried MongoDB 5.0.8 locally with the newest pymongo drivers and the errors are still very general.

Sadly the linked form to participate in the beta program says:

Sorry, this survey is not currently active.

Any idea how to start testing this cool stuff?

Hi @Ikar_Pohorsky and welcome to the community!!

Th Schema-Validation feature is now available from MongoDB version 5.0.0. The work was done in SERVER-20547.

For example on inserting the document using the below command:

db.sample.insertOne( { name: “Mihai”, year: 2019, major: “Computer Science” })

Following error is observed in MongoDB version 4.4.0 which appears to be less descriptive.

MongoServerError: Document failed validation

However, on latest MongoDb version 5.0.9, on insertion, the following error is observed:

MongoServerError: Document failed validation
Additional information: {
  failingDocumentId: ObjectId("62970b087ea0ed071328a4d4"),
  details: {
    operatorName: '$jsonSchema',
    schemaRulesNotSatisfied: [
      {
        operatorName: 'required',
        specifiedAs: { required: [ 'name', 'year', 'major', 'address' ] },
        missingProperties: [ 'address' ]
      }
    ]
  }
}

Let us know if you have further questions

Thanks
Aasawari

2 Likes

Thanks @Aasawari for the reply!

Maybe I’ll have to wait a bit. Currently on mongo 5.0.8 (ubuntu 18.04.6 LTS) using mongosh 1.4.2 and the validation error still says:

MongoServerError: Document failed validation

…no Additional information is showing up.

Is there any config option to enable the Additional info?

Hi @Ikar_Pohorsky

The feature is available on all versions post MongoDB version 5.0.0 and hence should be available on 5.0.8 too.
Could you please confirm if there is a possibility that the MongoDB has been upgraded from the 4.4 series to the 5.0 series?

There might be a possibility that the Feature Compatibility Version has not been upgraded during the MongoDB binary upgrade. The following documentation will help you to set the compatibility to version 5.0 using the command

db.adminCommand( { setFeatureCompatibilityVersion: “5.0” } )

I hope the above helps or else please let us know for further issue.

Thanks
Aasawari

2 Likes

That was it! Thank you so much @Aasawari :heart:

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.