JSON Schema Validation Rules
JSON Schema validation rules are a bunch of rules in a JSON format, that define which document can be added into a collection. The Schema can have rules, like the `age` property should have a minimum value of 18, and so the document, that we are trying to add, will fail to get inserted into the collection if it does not follow the said criteria in the Schema validation.
View Existing Validation Rules in MongoDB
MongoDB is a NoSQL database. MongoDB database can handle large, complex, and unstructured data with easy scalability. It allows us to make changes to the Schema as and when required. The Schema validation rules are a set of rules that are applied to the document when it is added to the collection. If the document adheres to the rules, then it is added, else the MongoDB throws a validation error that prohibits adding the document to the collection. MongoDB also allows us to view the existing schema validation rules that are applied to any collection.
We will be using Mongoose in the below example to understand and view the JSON Schema validation in a MongoDB collection. mongosh is a CLI provided by the MongoDB community itself to interact with its utilities and collections, i.e., without any GUI.
Contact Us