JSON-based schemas in MongoDB
There is a possibility that we may need the database's schema before the application development gets started. Or what if we want to set the data types for all the datasets with all kind of validations just like MySQL?
At this point, we are planning to structure and validate our NoSQL data. We are moving toward finding a framework that provides a wrapper around mongodb and which can yield such features with trusted community support.
Mongoose is a leading third-party framework that provides all kind of schema-based validations, virtual properties, and more.
Let us go through an approach for how JSON-based schemas are prepared and validated using mongoose
:
- Install mongoose via the following
npm
command:npm install mongoose --save
- As we are planning to implement mongoose in our application, we are going to use the wrapper methods provided by mongoose to connect to mongoDB
Not a big modification, simply comment the mongodb client from plugins.js
and include the following...