Mongoose is an elegant MongoDB object modeling library for Node.js. As I mentioned earlier, MongoDB is a schemaless database design. While this has its own advantages, sometimes we need to add certain validations as well, and this means defining the schemas for our documents. Mongoose provides an easy way to add such validations and to typecast the fields in a document.
For example, to insert data into a MongoDB document, we can use:
> db.posts.insert({ title : 'test title', description : 'test description'})
Now, if we want to add another document and we want an extra field in that document, we can use:
> db.posts.insert({ title : 'test title', description : 'test description', category: 'News'})
This is possible in MongoDB because no schemas are defined. These types of documents are also needed when...