Node.js - Connecting to MongoDB using MongoHQ on Heroku

谁都会走 提交于 2019-12-03 16:15:20

We are using heroku against MongoHQ but in our case we created the MongoHQ account on our own so our solution is a bit different. Now, we are using the Redis plugin and in that case we connect to Redis using the heroku env variables. When you create a new plugin, Heroku adds a bunch of env variables that you can access from your node.js app easily doing this:

process.env.NAME_OF_VAR

In the case of Redis to go the name of the var is REDISTOGO_URL so our code looks like

process.env.REDISTOGO_URL

For MongoHQ the env variable seems to be MONGOHQ_URL

You may need to do some parsing. Heroku have some documentation for Ruby here http://devcenter.heroku.com/articles/mongohq#using_the_mongo_ruby_driver that should help you to get it going.

With respect to where to do this in an express app. We are doing all the setup on app.js that is our entry point in the app.

Hope this helps.

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