Trying to do what the title says.
When I try to heroku open
I get Error: failed to connect to [localhost:27017]. I know this is because I don't have any database hooked up to my Heroku app. What I don't know is how to do that.
One tutorial said this snippet would work:
var mongo = require('mongodb');
var mongoUri = process.env.MONGOLAB_URI ||
process.env.MONGOHQ_URL ||
'mongodb://localhost/mydb';
mongo.Db.connect(mongoUri, function (err, db) {
db.collection('mydocs', function(er, collection) {
collection.insert({'mykey': 'myvalue'}, {safe: true}, function(er,rs) {
});
});
});
But I'm not sure where exactly to put it (app.js
?) or what mykey
and myvalue
are. I see MongoLab has a unique username and account name, but I can't find anything else. Where should I look/do to fix this problem?