Strata Gems: CouchDB in the browser

Get a feel for MapReduce without installing any software

We’re publishing a new Strata Gem each day all the way through to December 24. Yesterday’s Gem: Whirr makes Hadoop and Cassandra a snap.

Strata 2011 An earlier Strata Gem explained how to try MongoDB without installing any software. You can get a similar experience for CouchDB thanks to JSCouch, which also provides a great introduction to writing MapReduce functions.

CouchDB was the first document-store database to become popular under the “NoSQL” label, and offers some unique and interesting features.

  • RESTful JSON API — rather than requiring programming language-specific bindings, CouchDB can be accessed over HTTP, with JSON used as the data format
  • MapReduce — CouchDB provides query and view functionality via MapReduce operations, which are specified in JavaScript
  • Replication — with incremental replication and bi-directional conflict resolution, CouchDB is suitable for connecting replicated databases with intermittent connectivity. The Ubuntu One cloud service uses this feature

To demonstrate the basics of CouchDB, Mu Dynamics and Jan Lehnardt created a partial implementation of CouchDB that runs in the browser, JSCouch.

The sample database in the demonstration contains information about photos and their metadata, a few such documents are shown below.

If you click on the “map/reduce” tab, you will find a drop-down for selecting pre-written JavaScript functions for performing certain operations. Let’s take a look at a query to compute the sum of all the image sizes. Here’s the map function:

And the reduce function:

With a variety of NoSQL databases to choose from, and developers the unwitting kingmakers, easy demonstration interfaces such as JSCouch can help smooth the path to technology adoption.

tags: , , , ,

Get the O’Reilly Data Newsletter

Stay informed. Receive weekly insight from industry insiders.