                         "-u #{mongoConf.user} -p #{mongoConf.password} "+ 
                         "#{tempFile}",
               ->
+                fs.closeSync fd
                 fs.unlink tempFile 
                 console.log "Done"
 
+
         query.on 'end', -> pgclient.end()
 

          numProcessed++

          # assuming that stringify produces a one-liner
          jsonFile.write JSON.stringify(row) + "\n"


          if numProcessed >= totalRecordsNum

        numProcessed = 0


        #jsonFile = fs.createWriteStream(tempFile)
        fd = fs.openSync(tempFile, 'w')

        firstRow = true
        query = pgclient.query "SELECT * FROM aiddata2 #{if limit? then 'LIMIT '+limit}"
