How to run a mongo script from Heroku scheduler?

2019-07-18 15:21发布

I have implemented a javascript script for my mongo database. This script is called getMetrics.js and I am able to execute it by running: mongo getMetrics.js from my computer.

Now I want to automatically execute that script one time per day. To do so, I have created a Heroku app and I added to it the scheduler add-on (https://devcenter.heroku.com/articles/scheduler).

My main problem is that in order to be run, my task will execute the command "mongo getMetrics.js" and it will failed because I don't have mongo command installed in my Heroku app.

How can I run this script from Heroku?

Thanks a lot for your help.

1条回答
做自己的国王
2楼-- · 2019-07-18 15:53

I did the below in a similar case:

  1. Download mongodb for linux https://www.mongodb.com/download-center#community
  2. The bin folder contains the mongo binary
  3. Make this binary available in your Heroku instance (e.g. If you have your Heroku configured with your git repo, then checkin this binary along side your script

[Make sure the folder you are keeping this binary is in the path, safe path will be inside /bin]

查看更多
登录 后发表回答