节点+ mongo,不能插入到mongo,除非在本地主机上

出于某种原因,当我在本地运行时,以下插入到远程mongo服务器,但是当我在我的appfog服务器上运行它不插入。

function record_visit(req, res){ res.write("<br/>Connecting to "+mongourl+"<br/>"); mongo.connect(mongourl, function(err, conn){ res.write("<br/>mongo.connect success. Err = "+err+"<br/>"); conn.collection('ips', function(err, coll){ res.write("<br/>conn.collection called on collection ips, err = "+err+"<br/>"); object_to_insert = { 'ip': req.connection.remoteAddress, 'ts': new Date() }; coll.insert( object_to_insert, {safe:true}, function(err){ res.write("Inserted in collection 'ips' Err= "+err); res.end('<br/>Done\n'); }); }); }); } 

我的输出是:

 Connecting to [correct authenticated url to mongo here] mongo.connect success. Err = null conn.collection called on collection ips, err = null Inserted in collection 'ips' Err= null Done 

我是否需要在某处指定某些权限?

您可以尝试使用mongod上的–bind_ip arg将服务器绑定到机器的实际ip。 默认行为是监听所有本地IP,但是这可能并不意味着绑定到服务器的真实IP地址。

有几个原因可能导致无法连接到AppFog上的mongo服务。 这里是如何开始在AppFog上使用Mongo的文档URL:

http://docs.appfog.com/services/mongodb

如果这些文档不起作用,您可以通过support@appfog.com直接联系他们的支持人员,也可以直接从他们的在线谷歌用户组获得反馈: https : //groups.google.com/forum/#!forum / appfog用户