 
   # 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) ->
    data._id = docName
    mongo.collection(cName).insert data, callback

  close: ->
    throw new Error 'db already closed' if @closed
    mongo.close()
    @closed = true

  getSnapshot: (cName, docName, callback) ->
    throw new Error 'db already closed' if @closed
    mongo.collection(cName).findOne {_id:docName}, (err, data) ->
      delete data._id if data
      callback err, data

  setSnapshot: (cName, docName, data, callback) ->
    throw new Error 'db already closed' if @closed
    data.data = null if data.data is undefined
    data.type = null if data.type is undefined
    mongo.collection(cName).update {_id:docName}, {$set:data}, {upsert:true}, callback

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

    else
      query.$query._id = docName

    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
