           '--password', process.env["MONGODB_PASS"]
         ]
 
-      # remove trailing new line
-      mongoImportCmd = mongoImportCmd.match(/([\w\/]+)/)[0]
-
-      mongoimport = spawn mongoImportCmd, args
+      mongoimport = spawn mongoCmd, args
       mongoimport.stderr.on 'data', (data) ->
         logger.error "mongoimport error occured"
-      mongoimport.on 'exit', (code) ->
+      mongoimport.on 'close', (code) ->
         logger.info "mongoimport exited with code #{code}"
         doc =
           file: datetime

    scala: 'scala'
  map[lang]

importIntoMongodb = (datetime, callback) ->
  console.log "datetime #{datetime}"

  mongoImportCmd = ""

  which = spawn 'which', ["mongoimport"]
  which.stdout.on 'data', (data) ->
    mongoImportCmd = data.toString()
  which.on 'exit', (code) ->
    if (code is 0)
      args = [
        '--host', process.env['MONGODB_HOST']
        '--port', process.env['MONGODB_PORT']

        callback(code) if code isnt 0

        deleteArchiveFile(datetime)

deleteArchiveFile = (datetime) ->
  fs.unlink "#{archiveDir}/#{datetime}.json", (err) ->
