MongoDB断言错误“ECONNREFUSED”
AssertionError: null == {"name":"MongoError","message":"connect ECONNREFUSED"}
我有一个AssertionError。
我尝试使用NodeJS和MongoDB,我正在从Github的教程。
我从下面的代码中得到了这个错误:
var MongoClient = require('mongodb').MongoClient , assert = require('assert'); console.log(1); // Connection URL var url = 'mongodb://localhost:27017/myproject'; // Use connect method to connect to the Server MongoClient.connect(url, function(err, db) { console.log(2); assert.equal(null, err); console.log(3); console.log("Connected correctly to server"); db.close(); console.log(4); }); console.log(5);
在控制台,1,5,2被标记。
我安装了断言模块。 问题是什么?
我执行了“mongod”(实际上我不知道我是否正确)。 执行之后,1,5,2被标记,在此之前1,5,2没有被标记并且出错。
从ECONNREFUSED来看,我会说你的服务器没有运行。 如果您从控制台运行它,请尝试重新启动它。
为了运行服务器mkdir -p /data/db
然后sudo mongod
,它应该都运行良好。