Mongodb.js vs Mongoose, Why we chose Mongodb.js

NODE.JS AND THE API

For the contract I am currently working on, we are building an API using node.js, express.js and mongodb. For node.js to access data in a Mongodb database,  you need to have an library. There are several ways including the native mongodb driver, Mongoose, Mongolian Dead Beef, MongoSkin and I am sure there are tons I did not mention.

USING MONGOOSE

Mongoose brings schema’s and models to Node.js / Mongodb. Yes, it brings a schema to a NoSQL database. I think it makes no sense to do that. If you wanted models and schemas, go ahead and use MySQL.  Taking a database and putting schemas on top actually defeats the purpose.

One of the complaints I hear is that using Mongodb.js , developers have a problem with the joins and the schema. This is a problem with the developer, not with Mongodb or NoSQL databases in general.

DIFFERENCE BETWEEN THE TWO

Mongoose is higher level interface to Mongodb and actually uses mongodb.js,  the MongoDB driver. The question is not really which one is better or worse, the question for us is

Do the benefits of an ODM in Mongoose outweigh the drawbacks?

If you’re looking for an object modeling (ODM) tool so that you do not have to learn a lot about the way Mongodb works, then Mongoose is probably for you. If you want a fast driver and really get the most out of Mongodb, then use the native driver. We know our way around Mongodb so Mongoose would have slowed use down and our app.

BOTTOM LINE

If you are having a problem using schemas ( or complaining about joins )  in any NoSQL database, it is time to stop and spend a little bit more time understanding NoSQL databases and why they work the way they do.

Some of the things you get from Mongoose, validation, etc are good uses, I just think there are a lot better ways to do it in javascript than wrapping a NoSQL database in schemas.