Member-only story

Mongoose.js for MongoDB in a nutshell

Uday Hiwarale
4 min readJul 15, 2016

--

mongoDb is probably the best noSQL database out there which has flexible schema definition and uncapped variable storage of data.

When schema is flexible that mean when there isn’t any strict definition of how data should be stored, it needs lots of validation before documents can be inserted in a collection. And trust me it can be painful.

When working with node.js (JavaScript), there are many modules out there like mongoJS, mongoose, native mongodb driver etc., choosing the right one is a big task.

In this article, I am going to compare mongoJS and mongoose. And then explain top features of mongoose.

If you need mongodb shell like syntax to do CRUD operations, then go with mongoJS. It’s a good module to start with. But as I discussed earlier, when you are saving some document, you need to do validating and mongoJS doesn’t provide any feature to validate your data. Hence if you are working with express, you need to use some kind of body-parser validation which is not very generic to your mongoDB.

Then I thought let’s try mongoose. While learning mongoose, I felt so bad about myself that I was stupid to use mongoJS. It’s not like mongoJS is bad, it just that mongoose fit very well with my application than mongoJS.

--

--

No responses yet