1

I am hosting a node.js application on Heroku and trying to connect to MongoLab using the node module node-mongodb-native to connect. My application works fine when run from localhost connecting to MongoLab, but after deploying to Heroku I get an Application Error H12 (Request timeout).

Sample code:

app.get('/', function(req, res) {
    require('mongodb').connect(mongourl, function(err, conn){
        conn.collection('mycollection', function(err, coll){
            coll.find().toArray(function(error, results) {
                if(error) console.log(error)
                else {
                    res.send(util.inspect(results));
                }
            });
        });
    });
});

Are there additional options I need to pass to .connect() from Heroku?

Any suggestions are greatly appreciated. Thanks!

jcarrig
  • 83
  • 5
  • 1
    is `mongourl` returning the correct value? – Neil Middleton Mar 12 '12 at 17:08
  • hi i'm with MongoLab and would love to help. +1 what Neil said .. would be interested to know the value of `mongourl` -- masking out any password, naturally. – dampier Mar 12 '12 at 17:51
  • hi Neil, the mongourl is returning the correct value as far as i know. hi @dampier, here is the mongourl: mongodb://heroku_app3138529:mypassword@ds031407.mongolab.com:31407/heroku_app3138529 the strange thing that I can't figure out is that it works when I run the app from my local environment, but not from Heroku... – jcarrig Mar 13 '12 at 01:17

1 Answers1

0

In case anyone else has this issue:

It is now possible to choose what version of node you would like to run on Heroku. So by adding the following code to my package.json I was able to connect to MongoLab no problem:

"engines": {
  "node": "0.6.12"
, "npm": "1.1.4"
}

Thanks.

jcarrig
  • 83
  • 5
  • What was the problem? Did switching to an older version of node resolve it? – jcruz Jan 18 '13 at 18:25
  • I'm also unclear on this. I have the same issue, although I set my node value in the package.json (in my case to "0.10.x") So if this is some sort of node version issue I would appreciate a note. – darelf Aug 11 '13 at 01:28