                 fs.unlink tempFile 
                 console.log "Done"
 
-
-
         query.on 'end', -> pgclient.end()
 

      #pgclient.on('drain', pgclient.end.bind(pgclient))
      pgclient.connect()

      #limit = 10

      cntQuery = pgclient.query(
        if limit? 

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


          if numProcessed >= totalRecordsNum
            console.log "#{numProcessed} records were saved temporarily in #{tempFile}"
            console.log "Now importing into MongoDB"
            util.run "/usr/bin/mongoimport " +
                        "-d aiddata -c aiddata --upsert --upsertFields aiddata_id " +
                        "-u #{mongoConf.user} -p #{mongoConf.password} "+ 
