首页 新闻 会员 周边

使用 node.js 的 mongoose 模块连接 MongoDB 时出错

0
悬赏园豆:50 [待解决问题]

问题说明:

1、MongoDB(2.6.6版) 已经打开(绑定服务IP 以及 端口号均为默认)(未申请博客,不能上图)

 

2、nodejs(4.0.0版) 代码为:

var mongoose = require("mongoose");

mongoose.connect("mongodb://localhost/todo_development", function (err) {
    if (!err) {
        console.log("connected to MongoDB");
    } else {
        throw err;
    }
});

 

3、运行以上代码时报以下错误:

E:\nodejs\test\node_modules\.2.2.16@mongodb\lib\server.js:265

    process.nextTick(function () {throw err;})

MongoError: failed to connect to server [localhost:27017] on first connect at null.<anonymous>...............

 

请各位高人指点!!!

yamybl的主页 yamybl | 初学一级 | 园豆:77
提问于:2017-01-06 11:48
< >
分享
所有回答(2)
0

把localhost改成ip地址试试

创心coder | 园豆:736 (小虾三级) | 2017-01-06 12:52

试过的,不行。

支持(0) 反对(0) yamybl | 园豆:77 (初学一级) | 2017-01-06 13:11

@yamybl: 首先确认用shell能操作数据库,保证数据库服务没有问题。然后看看这个对你有没有帮助:

MONGODB NODE.JS DRIVER

支持(0) 反对(0) 创心coder | 园豆:736 (小虾三级) | 2017-01-06 13:26

@牧工:谢谢回复。 shell运行是正常的。

支持(0) 反对(0) yamybl | 园豆:77 (初学一级) | 2017-01-06 14:13
0

关于MongoDB使用node.js的问题,在MongoDB萌阔论坛上有相关讨论及介绍,你可以去看看,了解更多^^^^
萌阔论坛网址:http://forum.foxera.com/mongodb/topic/442/nodejs操作mongodb?un=Jesse

JesseShi | 园豆:274 (菜鸟二级) | 2017-06-06 10:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册