     putDirectory devicename, ".#{filePath}", false, (err, res) ->
 
         # Fetch only files with the same path/filename
-        db.db.query { map: (doc) -> emit doc._id, doc if doc.docType is 'File' }, (err, res) ->
+        db.query { map: (doc) -> emit doc._id, doc if doc.docType is 'File' }, (err, res) ->
             for doc in res.rows
                 doc = doc.value
                 if doc.name is fileName and doc.path is filePath

    urlParser = require 'url'
    url = urlParser.parse remoteConfig.url
    url.auth = "#{devicename}:#{remoteConfig.devicePassword}"
    replication = db.db.replicate.to(urlParser.format(url) + 'cozy', options)
      .on 'change', (info) ->
          console.log info
      .on 'complete', (info) ->

    urlParser = require 'url'
    url = urlParser.parse remoteConfig.url
    url.auth = devicename + ':' + remoteConfig.devicePassword
    replication = db.replicate.from(urlParser.format(url) + 'cozy', options)
      .on 'change', (info) ->
          console.log info
      .on 'complete', (info) ->
