How to use MongoDB with Node.js

MongoDB and Node.js belong to the same league - new age Web technologies that are shaking up the world of Web development. Both of them are revolutionary alternatives to the traditional technologies like MySQL and PHP. Combining Node.js and MongoDB could be the very best option for your next website or app. Now the question is how do you use MongoDB with Node.js?

Node.js has a huge collection of excellent module for many many purposes; naturally there are more than a dozen modules that are about integrating MongoDB with Node.js. Till something official comes from 10gen (the developers of MongoDB), it would be safe to say that these two modules stand out in the list.

MongoDB Native is an excellnt async Node interface to MongoDB, but it has an awkward interface with too many callbacks. Mongoose is an async JavaScript driver which is built with ORM on mind. When I am working with Node.js, I would like to keep ORM out of my mind.

So you see I have problem with both MongoDB Native and Mongoose.

Enter Mongoskin. Mongoskin is a future later on top of MongoDB Native, which presents a much improved interface to the driver. What it means is that you can now wield the awesome powers of MongoDB Native using a much better handle, which is Mongoskin.

Here is a simple example of how you might use Mongoskin in your Node.js code:

El neato? Mongoskin can do much more than that (obviously). I wrote a tutorial on Mongoskin for beginners, check it out. As of this moment, I would say Mongoskin is the way to go for Node.js-MongoDB integration.