MongoDB is an open source database that is very scalable and high performing, and is fast becoming one of the more popular NoSql implementations. It uses a data format known as BSON, which is syntactically similar JSON but is saved in binary form for speed; is schema free, meaning that documents belonging to the same store need not necessarily have the same structure; and can store dates, object ids, binary data, regular expressions and code as well as the basic JSON types of string, integer, boolean, double, null, array and object.

Installing Mongo is really simple:

  • create a mongo file (not necessary but tidy) [mkdir /mongo]
  • pull mongo [curl{{VERSION}}.tgz > mongo.tgz]
  • extract [tar xzf mongo.tgz]
  • create data file [mkdir -p /data/db/]
  • install [chown id -u /data/db]

Next install mongodb-php:

  • install dev tools (if necessary) [yum groupinstall "Developer Tools"]
  • check whether pecl needs upgrading (it did for me) and check mongo package available [pecl search mongo]
  • install [pecl install mongo] (if any problems, try creating mongo directory in /tmp)
  • restart apache [apachectl graceful]

If you’re anything like me, you’ll prefer a half-decent administration ui over the command line. I originally looked at phpMoAdmin, but for whatever reason it would die, giving me an HTTP 500 error when it did so but with no further guidance, every other time I accessed it (including navigating from page to page…). Even when it did work it looked awful and didn’t seem very friendly, so I gave up on that and installed RockMongo.

RockMongo was super simple to install – just a matter of cloning the respository onto the root of my server – and tweak the config if necessary (for me the defaults worked fine). The only problem that I had was that I couldn’t work out how to change the default username/password from admin/admin. It’s really easy though, was probably more to do with me being tired than it being complicated: simply change the line

$MONGO["servers"][$i]["control_users"]["admin"] = "admin";


$MONGO["servers"][$i]["control_users"][{{username}}] = {{password}};

in the config.php

I’ve been reading recently about the new HTML5 specs, and one thing that really interested me was the Web SQL Database spec that would allow javascript developers to access a client-side database from within the browser, in order to save and manipulate data locally on the users machine. This would enable interactive javascript web applications to run offline, in a similar manner to how Google Gears works (think storing emails for access at a time when no internet connection is available). The WebDB API defined a relational database that could be queried using SQL. Unfortunately, as of 18th November 2010, this spec was canned, because it suffered from one fatal flaw: it used SQL. The problem was that in order to define a cross-browser compatible API, all vendors would need to implement the same database (or more specifically, the same form of SQL). The spec pushed SQLLite as the database implementation, which both Chrome and Safari agreed with, but since Microsoft wanted to use a version of SQL Server in IE, work on the specification was ceased.

The replacement for the WebDB API was the Indexed Database API. Unlike webDB, this was a NoSQL database implementation, which used object stores rather than the typical relational database implementation. The main problem with the IndexedDB API, it seemed to me, however, was that the syntax was just awful compared to it’s SQL alternative. The code samples found at Mozilla Hacks show this pretty well (although it seems that the point of the post is supposed to sing the advantages of IndexedDB over WebDB!). This example, taken from that post, shows the different code samples required to load and display all the kids in a database that have bought candy:


var db = window.openDatabase("CandyDB", "1",
                             "My candy store database",
db.readTransaction(function(tx) {
  tx.executeSql("SELECT name, COUNT(candySales.kidId) " +
                "FROM kids " +
                "LEFT JOIN candySales " +
                "ON = candySales.kidId " +
                "GROUP BY;",
                function(tx, results) {
    var display = document.getElementById("purchaseList");
    var rows = results.rows;
    for (var index = 0; index < rows.length; index++) {
      var item = rows.item(index);
      display.textContent += ", " + + "bought " +
                             item.count + "pieces";


candyEaters = [];
function displayCandyEaters(event) {
  var display = document.getElementById("purchaseList");
  for (var i in candyEaters) {
    display.textContent += ", " + candyEaters[i].name + "bought " +
                           candyEaters[i].count + "pieces";

var request ="CandyDB",
                                    "My candy store database");
request.onsuccess = function(event) {
  var db = event.result;
  var transaction = db.transaction(["kids", "candySales"]);
  transaction.oncomplete = displayCandyEaters;

  var kidCursor;
  var saleCursor;
  var salesLoaded = false;
  var count;

  var kidsStore = transaction.objectStore("kids");
  kidsStore.openCursor().onsuccess = function(event) {
    kidCursor = event.result;
    count = 0;
  var salesStore = transaction.objectStore("candySales");
  var kidIndex = salesStore.index("kidId");
  kidIndex.openObjectCursor().onsuccess = function(event) {
    saleCursor = event.result;
    salesLoaded = true;
  function attemptWalk() {
    if (!kidCursor || !salesLoaded)

    if (saleCursor && == saleCursor.kidId) {
    else {
      candyEaters.push({ name:, count: count });

Pretty monstrous right? Which is a real shame, since IndexedDB has the potential to be a really, really useful in a client side developers toolkit.