     else
       query.$query._id = docName
 
-    mongo.collection(cName).findOne query, (err, result) ->
-      if result
-        result.docName = docName
-        delete result._id
-      callback err, result
+    mongo.collection(cName).findOne query, (err, doc) ->
+      callback err, castToSnapshot(doc)
 
   # Test whether an operation will make the document its applied to match the specified query.
   # This function doesn't really have enough information to know in all cases, but if we can determine


  # Test if a document matches a particular query. Should be synchronous and return true or false.
  #matchesQuery: null # (query, doc) ->


  name: 'mongo'

  create: (cName, docName, data, callback) ->
    return callback 'db already closed' if @closed
    doc = castToDoc docName, data
    mongo.collection(cName).insert doc, callback

  close: ->
    return callback 'db already closed' if @closed
    mongo.close()
    @closed = true

  getSnapshot: (cName, docName, callback) ->
    return callback 'db already closed' if @closed
    mongo.collection(cName).findOne {_id:docName}, (err, doc) ->
      callback err, castToSnapshot(doc)

  setSnapshot: (cName, docName, data, callback) ->
    return callback 'db already closed' if @closed
    doc = castToDoc docName, data
    mongo.collection(cName).update {_id:docName}, doc, {upsert:true}, callback

  query: (cName, inputQuery, callback) ->
    return callback 'db already closed' if @closed
