116

I'm looking for a database to pair with a node.js app. I'm assuming a json/nosql db would be preferable to a relational DB [I can do without any json/sql impedance mismatch]. I'm considering:

  • couchdb
  • mongodb
  • redis

Anyone have any views / war stories re compatiability/deployability of the above with node.js? Any clear favorites?

Jess
  • 23,901
  • 21
  • 124
  • 145
Justin
  • 4,649
  • 6
  • 33
  • 71
  • 2
    I think it would be helpful to answer the question if even broader requirements are mentioned. Each DB has its own pros, cons and speciality. Let us know the specs ! – Samyak Bhuta Oct 27 '11 at 18:55

11 Answers11

79

I'm the developer of the mongodb driver for node.js. I'm using mongodb for my own projects and have been very happy with the performance of mongodb.

Mongodb driver for node.js

(Shameless plug) Feel free to ask any questions about the driver at

Google group for the mongodb driver

or here at Stackoverflow

Have fun with node.js. I absolutely love the platform :D

kazinix
  • 28,987
  • 33
  • 107
  • 157
christkv
  • 4,370
  • 23
  • 21
  • 1
    also look at mongoose, which is a fairly nice ORM that builds on top of / uses the mongodb driver for node.js – taxilian Sep 23 '11 at 22:15
  • 2
    We are using Node.js + MongoDB for quite some time and it is going great. And full kudos to @christkv, the driver is rock solid and will not fail you. We have deployed the node.js/express.js + mongodb on EC2 with ease. Also, note that we are not using Mongoose. Talking about challenges (assuming you are already good at Node), you need to be good at Mongo way of doing the things (querying and aggregation ) for any serious application or service development. Learning how Mongo is different from other DBs would be really you should to first if you are still in evaluation stages. – Samyak Bhuta Oct 27 '11 at 18:49
  • from what I understand some really cool features are coming down the line to speed up aggregation in mongodb. One of them is native aggregation functions. http://www.slideshare.net/cwestin63/mongodb-aggregation-mongosf-may-2011 and also a possible switch to v8 instead of spidermonkey for the javascript engine which will allow each map-reduce command to run in it's own thread (bye bye singlethreaded map-reduce) – christkv Dec 03 '11 at 13:46
25

Although your choice very much depends on the features you are going for, I really appreciate CouchDB for its native JavaScript environment. Both data and views are written in JavaScript so it fits very well to node.js in my opinion.

There are also different client libraries available, some are rather low level, other really very abstracted.

But as I said, you should also think about the features that you require for your database.

Nosredna
  • 83,000
  • 15
  • 95
  • 122
b_erb
  • 20,932
  • 8
  • 55
  • 64
18

Redis is a popular choice. What you're after is a database driver that doesn't block.

The databases you listed are all very different. Redis takes the idea of key-value storages and runs with it, adding a variety of data types and ways of querying data. People often note that redis scales down very well too; meaning that it has very low overhead despite having the ability to perform.

Here is a list of available database modules: http://wiki.github.com/ry/node/modules#database

Jökull
  • 503
  • 5
  • 9
  • Yes Redis is great but it seems we can store binary data but cannot retrieve that! Atleast I couldn't find any Redis command for binary data. – AppleGrew Apr 11 '11 at 06:22
  • Really? I used to store binary data (using Node's Buffer class) and it worked fine. What version of Redis/Node? – DanielS Sep 04 '11 at 06:54
  • 12
    By default, node_redis will return JavaScript strings for all commands. To get buffers instead, create a client with createClient(port, host, { return_buffers: true }); – Matt Ranney Sep 20 '11 at 06:40
  • 4
    @MattRanney, You save just saved me hours more of digging! I didn't see this anywhere in the node-Redis docs and literally time-sunk 5 hours. My appreciation is without limit in this moment. – hayesgm Oct 26 '11 at 08:08
  • well all sounds good in theory but take a practical example , you have a JSON API that you query every 20 seconds which returns an array, you wanna be able to cache this, would you still go with Redis? also gotta do a fuzzy search through this array – PirateApp Dec 20 '17 at 15:30
15

I really like CouchDB. It's a bit of a learning curve, but views are really powerful once you understand how to use them. There is a module called cradle on github and npm that is really easy to work with. I haven't been able to test how fast it is, but it is really flexible (you can access your data in a browser too if you'd like).

The major issue here is which database design makes sense for your application. Do you have data that is largely key-value in nature? If so, use Redis. Do you have data where not all documents necessarily have the same fields? If so, use a NoSQL database like CouchDB.

The next worse thing to using a blocking database is using the wrong database for your data. CouchDB is managed by Apache, so you know that it's good quality, but it doesn't make sense to use it if your data would make more sense in an SQL table or a simple key-value store.

Think of your use case. Will you be more likely to want to do a full-text search, just get data by key, or get ranges of documents that have similar attributes?

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
beatgammit
  • 19,817
  • 19
  • 86
  • 129
8

Might want to check out Persistence, high level persistance/database system for node.js.

from thechangelog.com:

Persistence is a project to allow a high level API for persisting data between process runs. The goal is to support backends that are easy to use, powerful, flexible, or all of the above if possible.

Supported databases include:

  • PostgreSQL - An enterprise level relational database. The driver is implemented in pure JavaScript and communicates over TCP using the PostgreSQL wire protocol.
  • Sqlite3 - A simple, fast, server-less relational database. This driver is a wrapper around the command-line sqlite3 program. It requires sqlite3 to be in the path. The communication is extremely fast, but types aren’t very precise. There are only strings and nulls returned.
  • MongoDB - A scalable, high-performance, open source, schema-free, document-oriented database. This driver also implements the wire protocol in JavaScript and communicated with the server over TCP.
  • JSON-DB - A homegrown system schema-free, document-oriented database that uses simple flat files containing JSON objects. This has no requirements at all except node and a filesystem. Performance is to be determined once it’s implemented fully.
Gary S. Weaver
  • 7,966
  • 4
  • 37
  • 61
  • 13
    Persistence hasn't been updated since March 2010 and is on release 0.0.4, so it seems like it might have been abandoned. – lacker Sep 29 '10 at 19:10
5

Disclaimer: I'm the author.

Perhaps have a look at BarricaneDB announced here.

fadedbee
  • 42,671
  • 44
  • 178
  • 308
3

I'm not sure the correct solution is to solely focus on mapping a database to your web stack, but rather also considering application-specific requirements.

Are you analyzing twitter feeds or other high-volume data for patterns, but don't need transactional support? Then pick something really fast.

Do you just want to store some really basic info in a few tables and its currently not an "enterprise focused" app? Then pick something cool to learn.

Maybe you are going to store data thats really important to a client, robust, needs to be transactional, and have live replication to remote hosting facilities, etc. Then maybe look at something like postgresql. It wouldn't mirror as well, but the node.js driver works pretty well and if you aren't deathly afraid of sql it gets what you want in/out pretty easily.

As for my own opinion, I think going with a newer stack like node.js (vs traditional frameworks in php/java) is adding enough "new" complexity that one shouldn't add extra layers all at once. This is a good article that discusses that:

http://nodeguide.com/convincing_the_boss.html

qooleot
  • 409
  • 4
  • 9
2

I'll speak from my experience: CouchDB comes with a definite learning curve, whereas MongoDB I found to be very easy to learn and set up. I have never used redis. I suggest MongoDB - but that maybe shameless fanboyism - I have no numbers, heh, only claims of ease of use.

PinkElephantsOnParade
  • 6,452
  • 12
  • 53
  • 91
1

dirty is yet another flat-file key-value store. As the name suggests, it's a quick and dirty but performant solution for simple cases. I'm not the author :)

nponeccop
  • 13,527
  • 1
  • 44
  • 106
1

Some more to consider:

Globals: http://globalsdb.org

GT.M (see https://github.com/robtweed/node-mwire for a starting point)

M/DB (an open source clone of SimpleDB): https://github.com/robtweed/node-mdb and you can use the Node.js SimpleDB client to access it: https://github.com/rjrodger/simpledb

Rob Tweed
  • 79
  • 1
0

I found CouchDB very easy to master. There are a lot ebooks available on the internet which will teach you how to use CouchDB with Node.js.

I found this book very useful for learning CouchDB.

For using CouchDB with Node.js, I use NANO module.

CouchDB can be hosted on either Iriscouch or Cloudant.

Shekhar
  • 910
  • 1
  • 13
  • 23