         numProcessed = 0
 
 
-        jsonFile = fs.createWriteStream(tempFile)
+        #jsonFile = fs.createWriteStream(tempFile)
+        fd = fs.openSync(tempFile, 'w')
 
         firstRow = true
         query = pgclient.query "SELECT * FROM aiddata2 #{if limit? then 'LIMIT '+limit}"

          numProcessed++

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


          if numProcessed >= totalRecordsNum

                        "-u #{mongoConf.user} -p #{mongoConf.password} "+ 
                        "#{tempFile}",
              ->
                fs.closeSync fd
                fs.unlink tempFile 
                console.log "Done"


        query.on 'end', -> pgclient.end()

