Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Validation using latest JSON Schema version?

When will MongoDB support validation using the latest JSON Schema standard, which is draft 2019-09.

Currently MongoDB only supports JSON Schema Draft 4, which is pretty long in the tooth.

Thanks!

Welcome to the community @Andrzej_Taramina!

What specific features are you interested in using from the newer JSON Schema drafts?

Updating isn’t straightforward as there are backward-incompatible changes. For example, see: Changes between draft-04 and draft-06.

There are already some tracking issues for features that may be of interest to upvote and watch:

Regards,
Stennie

Thanks for the pointer to this theead. As the JSON Schema spec moves towards RFC recognition, it is helpful if json databae like mongo supports it. It should be the standard way for doing Jaon data validation. Otherwise devlopers can use validation libraries before Creates and updates. But much better if Mongo handles it. I am looking at the HL7 FHIR schema which conforms to draft 6. The combination of json achema and mongos native json document collections can prove a powerful comination in implementing complex data models like FHIR.

Hi @Richard_Braman,

Thanks for the practical example of HL7 FHIR schema, which currently appears to target JSON Schema draft-06. Draft-06 is newer than MongoDB’s server implementation of draft-04 but older than the latest 2019-09 JSON Schema draft. As noted in my earlier comment on this topic, there are some backwards-incompatible changes between different versions of JSON Schema. Draft specifications are unfortunately a moving target, but I expect JSON Schema will generally have more consistent implementation versions after an RFC has been proposed & adopted by the IETF.

JSON Schema support required for HL7 FHIR would be a good example to include in a feature suggestion on the MongoDB Feedback Engine so others can upvote & comment on the idea.

In the interim, some workarounds would be to either incorporate a JSON Schema draft-06 validation library in your application tier or transform draft-06 schema into declarations compatible with the current MongoDB server implementation. Even with schema validation support at the database server level, I would recommend validating in your application layer to avoid the extra network round trip and provide more informative validation messages. However, it would be more ideal to share a single definition of JSON Schema across multiple validation layers in your stack.

You may also be interested in Building FHIR Applications with MongoDB Atlas, which describes an open source FHIR server (MIT licensed) based on MongoDB.

It is worth noting that MongoDB supports JSON-like data structures, but is not a JSON database. MongoDB’s underlying data format is BSON, a Binary JSON-like data format that represents data with richer data types than those available in JSON. For example, BSON has extended numeric types including int32, int64, double, and Decimal128 whereas JSON only has a generic Number (aka double) type. MongoDB extends JSON Schema with a bsonType keyword to specify data types.

Regards,
Stennie