30

I'm getting more into Node.js and am enjoying it. I'm moving more into web application development.

I have wrapped my head around Node.js and currently using Backbone for the front end. I'm making a few applications that uses Backbone to communicate with the server using a RESTful API. In Node.js, I will be using the Express framework.

I'm reaching a point where I need a simple database on the server. I'm used to PostgreSQL and MySQL with Django, but what I'm needing here is some simple data storage etc. I know about CouchDB, MongoDB and Redis, but I'm just not sure which one to use?

Is any one of them better suited for Node.js? Is any one of them better for beginners, moving from relational databases? I'm just needing some guidance on which to choose, I've come this far, but when it's coming to these sort of databases, I'm just not sure...

Community
  • 1
  • 1
littlejim84
  • 9,071
  • 15
  • 54
  • 77
  • For me the question is [Mongoose](http://mongoosejs.com/) vs [Cradle](http://cloudhead.io/cradle) – Raynos Jun 28 '11 at 14:47
  • @Raynos Thank you, didn't know about Cradle. I suppose everyone and their dog is using these database abstractions with Node JS, rather than directly communicating with the database's documented API? – littlejim84 Jun 29 '11 at 08:34
  • the problem I find with direct communication to the database is it's easy to get stuck in callback hell. You generally nest 4 levels of callbacks deep before you do anything. The API is simply not elegant and you should either use an existing abstraction or write your own. – Raynos Jun 29 '11 at 08:43

1 Answers1

56

Is any one of them better suited for Node JS?

Better suited especially for node.js probably no, but each of them is better suited for certain scenarios based on your application needs or use cases.

Redis is an advanced key-value store and probably the fastest one among the three NoSQL solutions. Besides basic key data manipulation it supports rich data structures such as lists, sets, hashes or pub/sub functionality which can be really handy, namely in statistics or other real-time madness. It however lacks some sort of querying language.

CouchDB is document oriented store which is very durable, offers MVCC, REST interface, great replication system and map-reduce querying. It can be used for wide area of scenarios and substitute your RDBMS, however if you are used to ad hoc SQL queries then you may have certain problems with it's map-reduce views.

MongoDB is also document oriented store like CouchDB and it supports ad hoc querying besides map-reduce which is probably one of the crucial features why people searching for DRBMS substitution choose MongoDB over the other NoSQL solutions.

Is any one of them better for beginners, moving from relational databases?

Since you are coming from the RDBMS world and you are probably used to SQL then, I think, you should go with the Mongodb because, unlike Redis or CouchDB, it supports ad hoc queries and the querying mechanism is similar to SQL. However there may be areas, depending on your application scenarios, where Redis or CouchDB may be better suited to do the job.

yojimbo87
  • 65,684
  • 25
  • 123
  • 131
  • Thank you. That is a superb answer. I was searching around for concise, real use scenarios for each of them, and you summed them up nicely for me to digest. Thank you. – littlejim84 Jun 28 '11 at 15:47
  • 1
    Mention couch exposes itself over REST! cmon! – Raynos Jun 28 '11 at 16:00
  • @raynos @yojimbo87 So seeing that CouchDB has a RESTful interface, does that mean I could directly communicate with it from Backbone on the front end? Surely I still need to GET from Node, and Node will then GET from CouchDB? ...what advantages does a RESTful interface have in a database? – littlejim84 Jun 28 '11 at 16:12
  • 1
    @littlejim84 You can talk to it directly. [backbone-couch](http://janmonschke.com/backbone-couchdb/). No server required. Of course you lose a lot of flexibility. Also don't confuse RESTful with REST. REST has a lot of advantages like taking advantage of HTTP. Go read any good article on REST. – Raynos Jun 28 '11 at 16:15
  • @raynos I am a little misty on REST. After you said that, I looked around and found this link http://tomayko.com/writings/rest-to-my-wife ...it's helped a lot! Also, going on @yojimbo87 it seems MongoDB will be great for me to start with. And seeing that the LearnBoost guys have made the lovely looking Mongoose to go with it, I think this solution will be perfect for me to get a NoSQL database going in my experimental Node JS application. Thank you! – littlejim84 Jun 28 '11 at 17:16