从Heroku连接到MongoLab时,应用程序超时 [英] application times out when connecting to MongoLab from Heroku

查看:98
本文介绍了从Heroku连接到MongoLab时,应用程序超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上托管一个node.js应用程序,并尝试使用节点模块node-mongodb-native连接到MongoLab以进行连接。我的应用程序在从连接到MongoLab的本地主机上运行时工作正常,但是在部署到Heroku之后,我得到一个应用程序错误H12(请求超时)。

示例代码:


$ b $

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

是否有其他选项需要传递给。 b
$ b

非常感谢任何建议。

解决方案

如果有其他人有这个问题:



现在可以选择你想在Heroku上运行的节点版本。所以通过将下面的代码添加到我的package.json中,我能够连接到MongoLab没有问题:

 engines:{ 
node:0.6.12
,npm:1.1.4
}

谢谢。


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!

解决方案

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.

这篇关于从Heroku连接到MongoLab时,应用程序超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆