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.

  • http://people.csail.mit.edu/karger David Karger

    I’ve always been a fan of keeping things simple and in the browser. Along the lines of the photo browser you describe, we built a general-purpose information management tool that lives entirely in a web page. It includes a database, rich information visualizations (lists, albums, maps, timelines, charts), faceted browsing, and a WYSIWYG editor (based on tinymce) that lets you modify the way the information is presented. After you edit it, you persist the changes to the data and visualization by saving the web page.

    You can try it out at http://projects.csail.mit.edu/exhibit/Dido . It would be fun to combine it with couchDB, which would give it access to more powerful query operators than the ones we’ve implemented.