Purpose of the schema validation "description" field


Is there any usage of the description field in schema validation?
For example, is there any way that Mongo prints the description field of properties that failed validation?
If not, I’m not sure of the purpose of this property. Maybe I’m not using it correctly but setting it as “must be a string and is required” like it’s shown in the MongoDB manual is redundant.

Does someone have a good usage of this property?

Welcome to the MongoDB Community @Hugh_Chocart!

The description field is part of the JSON Schema specification. This isn’t used by the current production MongoDB server release (4.4), but may still be useful for admin tools and JSON Schema Validators called from your application code.

Data validation should ideally happen as early as possible in the user experience (front-end, then application server) to provide responsive feedback to the end user. Validation by the database server should be the last gate before data is inserted or modified.

MongoDB’s JSON Schema implementation includes some minor Extensions and Omissions, but a collection’s JSON Schema validator can be used as the basis for earlier validation with a more informative client library.

Server-side support for more descriptive JSON Schema validation errors (SERVER-20547: Expose the reason an operation fails document validation) has been merged into the unstable/development branch of MongoDB (4.9.0) and will be included in the next major release (MongoDB 5.0) that is planned for later this year.

With MongoDB 5.0, releases will also shift to a shorter release cycle with quarterly releases and annual Long Term Support (LTS) releases: Accelerating Delivery with a New Quarterly Release Cycle, Starting with MongoDB 5.0.


1 Like

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