【发布时间】:2014-04-19 23:55:41
【问题描述】:
我正在尝试在 ec2 实例上运行我的应用程序。每次我启动它都会引发错误。似乎无法连接到我的 mongodb 数据库。我已经通过 npm 安装了 mongoose 和 mongodb。我在与服务器相同的 ec2 实例上运行 mongodb。我已经向我的 ec2 安全组添加了一个自定义 tcp 规则,以允许端口 27017 上的传入流量。
谁能帮我找出问题所在?在过去的 3 个小时里,我一直在尝试修复它。
这是我连接到 mongodb 的代码:
var mongoose = require('mongoose');
var db = mongoose.createConnection('localhost', 'app');
这是我不断收到的错误:
ubuntu@:~/app$ node app.js
info - socket.io started
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Express server listening on port 8080
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
at null.<anonymous> (/home/ubuntu/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:553:74)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (/home/ubuntu/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/home/ubuntu/polls/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
【问题讨论】:
-
您可以尝试提供 IP 地址而不是 localhost 吗?
标签: node.js mongodb amazon-web-services amazon-ec2 mongoose