How to run a mongo script from Heroku scheduler?

点点圈 提交于 2019-12-23 23:36:50

问题


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:


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]



来源:https://stackoverflow.com/questions/33354070/how-to-run-a-mongo-script-from-heroku-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!