 
   client = new mongodb.Db(options.db, new mongodb.Server(options.hostname, options.port, options.mongoOptions))
 
-  checked = false
-  checkIndex = (callback) ->
-    return callback?() if checked
-
-    client.ensureIndex 'docs', 'docName', {unique: true}, (err1, name) ->
-      console.warn "failed to ensure mongo index on docs collection: #{err1}" if err1
-
-      client.ensureIndex 'ops', {docName: 1, v: 1}, {unique: true}, (err2, name) ->
-        console.warn "failed to ensure mongo index on ops collection: #{err2}" if err2
-
-        checked = true if not err1 and not err2
-        callback?(err1 or err2 or null)
-      
+  client.ensureIndex 'ops', {docName: 1, v: 1}, {unique: true}, (err, name) ->
+    console.warn "failed to ensure mongo index on ops collection: #{err}\nperformance may suffer" if err
 
   # Creates a new document.
   # data = {snapshot, type:typename, [meta]}
   @create = (docName, data, callback) ->
-    checkIndex (err) ->
+    client.collection 'docs', (err, collection) ->
       return callback? err if err
-      client.collection 'docs', (err, collection) ->
+      
+      doc =
+        _id: docName
+        data: data
+      
+      collection.insert doc, safe: true, (err, doc) ->
+        if err?.code == 11000
+          return callback? "Document already exists"
+          
+        console.warn "failed to create new doc: #{err}" if err
         return callback? err if err
-      
-        doc =
-          docName: docName
-          data: data
-      
-        collection.insert doc, safe: true, (err, doc) ->
-          if err?.code == 11000
-            return callback? "Document already exists"
-          
-          console.warn "failed to create new doc: #{err}" if err
-          return callback? err if err
         
-          callback?()
+        callback?()
                 
   # Get all ops with version = start to version = end, noninclusive.
   # end is trimmed to the size of the document.

#
# The mongodb database contains two collections:
#
# - 'docs': document snapshots with 'docName' set to document name.
# - 'ops': document ops with 'docName' defined and version stored in 'v'.
#
# This implementation isn't written to support multiple frontends
# talking to a single mongo backend.

  # ... and that would slow it down a bit.)
  @writeOp = (docName, opData, callback) ->
    # ****** NOT SAFE FOR MULTIPLE PROCESSES. Rewrite me using transactions or something.
    client.collection 'ops', (err, collection) ->
      return callback? err if err
      
      doc = 
        docName: docName
        opData:
          op: opData.op
          meta: opData.meta
        v: opData.v
      
      collection.insert doc, safe: true, (err, doc) ->
        console.warn "failed to save op #{opData} for #{docName}: #{err}" if err
        return callback? err if err

        callback? null, doc
      
  # Write new snapshot data to the database.
  #
