           # assuming that stringify produces a one-liner
           jsonFile.write JSON.stringify(row) + "\n"
 
+
           if numProcessed >= totalRecordsNum
-            console.log "Read in: #{numProcessed}"
+            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} "+ 

@run = ->
  
  fs = require 'fs'
  util = (require '../cakeutils').include()

  #mongo = require 'mongodb'
  mongoConf = require('../.dbconf').mongodb

  pg = require 'pg'
  pgurl = require('../.dbconf').postgres


  runImportTasks = (importTasks) ->
    for taskName, importFunc of importTasks
      console.log ">>>>>>>>>> Importing '#{taskName}' >>>>>>>>>>"
      importFunc()


  runImportTasks

    aiddata : ->    
      tempDir = "data/temp"
      tempFile = tempDir + "/_aiddata.json" 
      util.mkdir tempDir

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


      cntQuery = pgclient.query(
        if limit? 
