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

        numProcessed = 0


        jsonFile = fs.createWriteStream(tempFile)

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

          numProcessed++

          # assuming that stringify produces a one-liner
          fs.writeSync fd, JSON.stringify(row) + "\n"

          if numProcessed % 1000 == 0
            console.log "Processed #{numProcessed} of #{totalRecordsNum}"


          if numProcessed >= totalRecordsNum
