Can I update a schema?

Hi @Kevin_Izevbigie,

Borrowing from discussion on a similar question in the context of the Node.js driver (How to use MongoDB for nodejs to modify the schema of an existing collection? - #2 by Stennie_X):

The essential step is:

… and a handy hint for previewing the effects of a schema validation change:

Lastly, schema validation in MongoDB 5.0+ has improved error messages that will help you understand why a document fails schema validation: Improved Error Messages for Schema Validation in MongoDB 5.0 | MongoDB.

If you happen to be using an older version of MongoDB server or would be like to validate earlier in your application logic (eg frontend or application code), you should be able to find a JSON Schema Validator library or package in your preferred implementation language. MongoDB’s JSON Schema implementation adds the bsonType keyword and has a few omissions, but should be straightforward to add if not already supported by your chosen validation package.

Regards,
Stennie

2 Likes