   #
   # This function has UNDEFINED BEHAVIOUR if you call append before calling create().
   @writeSnapshot = (docName, data, dbMeta, callback) ->
-    checkIndex ->
+    checkIndex (err) ->
+      return callback? err if err
       client.collection 'docs', (err, collection) ->
         return callback? err if err
       

  hostname: '127.0.0.1'
  port: 27017
  mongoOptions: {auto_reconnect: true}
}

# Valid options as above.
module.exports = MongoDb = (options) ->

  # Creates a new document.
  # data = {snapshot, type:typename, [meta]}
  @create = (docName, data, callback) ->
    checkIndex (err) ->
      return callback? err if err
      client.collection 'docs', (err, collection) ->
        return callback? err if err
      
