How to configure StrongLoop LoopBack MongoDB datasource for deployment to Heroku
This has now (as of June 27 2014) been addressed: create a file datasources.local.js
with the following content (where mongodb
is your data source name):
var mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || 'mongodb://localhost/mydb';module.exports = { mongodb: { defaultForType: "mongodb", connector: "loopback-connector-mongodb", url: mongoUri }};
Note: datasources.json
is still required (can be empty) and the .js
overrides the configuration in the .json
file.
This is a TODO for LoopBack to support configuration of datasources/models from environment variables and other sources. One idea is to use a template engine to load datasources.json so that it can have variables to be resolved at runtime.
Related to your question, LoopBack allows you to configure the datasource using a 'url' property. For example:
{ "connector": "loopback-connector-mongodb", "url": "mongodb://localhost:27017/mydb" }
As a workaround, you can write a post-deployment script for Heroku to replace the url value with process.env.MONGOLAB_URI or process.env.MONGOHQ_URL.
sed -i.bak s/MONGODB_URL/$MONGOHQ_URL/g datasources.json
Meanwhile, please open an issue at https://github.com/strongloop/loopback/issues.