 # A super simple mongodb adapter for itsalive
+
+shallowClone = (object) ->
+  out = {}
+  out[key] = object[key] for key of object
+  return out
 
 # mongo is a mongoskin client. Create with:
 #  mongo.db('localhost:27017/tx?auto_reconnect', safe:true)

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

    skip = query.$skip
    #delete query.$skip
    limit = query.$limit
    #delete query.$limit

    mongo.collection(cName).find query, (err, cursor) ->
      return callback err if err



  queryDoc: (cName, docName, query, callback) ->
    if query._id
      return callback() if query._id isnt docName
    else
      # Clone the query so we don't edit the original
      query = shallowClone query
      query._id = docName unless query._id

    mongo.collection(cName).findOne query, (err, result) ->
      if result
        result.docName = docName
