In the last few years there has been a proliferation of noSQL databases. Searching on Google for
site:news.ycombinator.com nosql yields over 2,500 hits, many of which include include posts asking when you’d want to use a noSQL database. If you’re used to a relational database it might seem like an unnecessary burden to learn another database paradigm, but there’s one open source noSQL database that I think is not only worth the burden, but is a perfect fit for Node.js development: Riak (pronounced “REE-ack”).
JSON.parse() when retrieving.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
In the above example, a riak-js client is created and a post object is created. The post object is saved into the ‘posts’ bucket, with its id as its key. To retrieve the post, the bucket and key are referenced.
If you decided to use Backbone.js on the server, calling
toJSON() on a Backbone model would allow you to easily store the model in the Riak.
Additional Features of Riak
1 2 3 4 5 6 7 8
Another interesting property of Riak, is it’s concepts of links. A link establishes a “one-way relationships between objects in Riak”. For instance, say we wanted to link similar posts the following would do:
1 2 3 4 5 6 7 8 9 10 11 12