When should we Modify Schema Validation in MongoDB?

As there are changes in data requirements or the business logic, schema validation rules are modified.

Points to remember:

  1. Initially, valid documents can change to invalid after modification in validation rules if they don’t satisfy the new rule.
  2. Validation rules can be applied to a collection that was defined without validation rules.

Modify Schema Validation in MongoDB

MongoDB was released in February 2009. It is an open-source document-oriented database. It is classified as a NoSQL database. The structure of the data in the collection is dynamic. It follows the CAP theorem (Consistency Availability and Partition tolerance). It is an unstructured language and provides horizontal scalability and high-performance, data persistence. It solved the problem of scalability and agility.

Similar Reads

Validation Rule in MongoDB

Validation rules decide the structure of the collection. The documents that satisfy the Validation rule are called valid documents and those that don’t satisfy are invalid documents. Validation rules can be changed at any time. Validation rules are modified using the collMod command in the validator object. Validation level, Validation rules, and Validation action can be also modified....

When should we Modify Schema Validation in MongoDB?

As there are changes in data requirements or the business logic, schema validation rules are modified....

Steps to Modify Schema Validation in MongoDB

Create a collection with validation. Modify the validation schema....

Results

1. Insert an Invalid Document...

Conclusion

Schema Validation decide the structure of the documents in MongoDB. Validation rules are modified using collMod command. Modified schema results in three outcomes ,which are handled and thus the process is completed. This helps to meet the current requirements, to ensure consistency and correctness to the documents....

Contact Us