【发布时间】:2016-11-05 20:49:20
【问题描述】:
我在 Ubuntu 16.04 中使用 mongo db node 和 express 创建了一个简单的服务,以将数据返回到 angular 2 应用程序。
我有一个名为 server.js 的文件,它连接到一个本地 mongodb 实例,其中包含一个名为 game 的数据库和一个名为 player 的集合。它安装在我的本地机器上运行良好。但是我正在尝试在亚马逊 ec2 上使用 Bitnami 的平均堆栈图像部署它。 (嘴巴满了)。我已经按照this guide正确设置了端口,可以远程连接。但是,我无法让猫鼬连接到任何数据库。这是我在本地机器上运行的代码。
mongoose.connect('mongodb://localhost:27017/game');
router.route('/player')
.get(function(req, res) {
console.log(mongoose.connection.readyState);
Player.find({"player":user,"password":password},function(err, Test) {
if (err)
res.send(err);
res.json(Test);
});
});
这是我为平均堆栈图像调整后的代码
mongoose.connect('mongodb://root:"My-Root-Password@127.0.0.1:27017/game');
router.route('/player')
.get(function(req, res) {
console.log(mongoose.connection.readyState);
Player.find({"player":user,"password":password},function(err, Test) {
if (err)
res.send(err);
res.json(Test);
});
});
在我的本地机器上,console.log 上的值为 1,平均堆栈图像上的值为 0。我不确定如何使用 mongoose 连接到 bitnami 的 mongo 实例。我已经检查了该游戏是否存在并且有我想要的数据。
【问题讨论】:
标签: node.js mongodb amazon-ec2 mongoose bitnami