First try with RethinkDB

I just wrapped up a project where we wanted to store some statistical data and a team member said they wanted to use MongoDB or RethinkDB. I recommended CouchDB for it but I wanted to see what RethinkDB was and if it was a good fit.

I discovered it has query language called ReQL and other interesting features. I used it both locally and on a hosting service called

brew install rethinkdb
npm install rethinkdb

It will launch an admin interface on port 8080. (Example images below)

Since the API I was writing was a node app I used the default driver offered by the group who does RethinkDB. The driver enables connection to the server and queries via ReQL. There are other drivers including one with connection pooling and other ORMs. In this case I wasn’t concerned about more advanced features and we were only implementing a few simple calls.


var r = require('rethinkdb'),
r.connect(api.config, function(err, connection) {
    if (err) {
        // connect error
    // connected
    con = connection

Write a ReQL query

    .filter({ user: 'tbone' })
    .filter({ ip: '' })
.run(con, function(err, cursor) {
    if (err) {
        // error running query
    cursor.each(function(err, row) {
        if (err) {
            // row error
        // do something with the data
    }, function(err) {
        // iteration via each complete

As you can see it’s all pretty straightforward. By now many of us are accustomed to the chained style of function calls on JS APIs. The only problem I had was trying to query on the timestamps. I experimented with date strings, ISO8601 dates, and finally ended up with UNIX timestamps.

There are many features I’ll continue learning about including how to watch for real-time changes to tables. It was a pleasant experience all-in-all implementing this project using RethinkDB. We got the job done and it works well even at load.

rethinkdb admin query

rethinkdb admin interface

Home Archive atom.xml Hexo⤴