简体   繁体   中英

MongoDB assertion error “ECONNREFUSED”

AssertionError: null == {"name":"MongoError","message":"connect ECONNREFUSED"}

I got an AssertionError.

I try to use NodeJS AND MongoDB and I'm following tutorial from Github.

I got that error from this code below :

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);

At console, 1,5,2 is marked.

I installed assertion module. What is the problem?

I executed 'mongod' (actually I don't know if I did it correctly). After executing, 1,5,2 is marked, before that, 1,5,2 is not marked and got an error.

Judging from the ECONNREFUSED, I would say your server is not running. If you are running it from console, try re-starting it.

为了运行服务器mkdir -p /data/db然后sudo mongod ,它应该都运行良好。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM