// Create a new MongoClient
const client = new MongoClient(url);
// Use connect method to connect to the Server
client.connect(function(err) {
assert.equal(null, err);
console.log(“Connected successfully to server”);
const db = client.db(dbName);
client.close();
});
I run mongod and in other tab when i run node app.js then i am getiing this below errorCcn Any one please fix this or help me in fixing this
It looks like it’s trying to connect on an IPv6 interface, but this is failing (ECONNREFUSED ::1::27017). The driver won’t fall back to IPv4 in these cases (see NODE-4678) so a quick fix is to change your connection string to "mongodb://127.0.0.1:27017" and reconfigure your replicaset (replSetReconfig) so the host details also reference the IP address.
For example (from the shell):
c = rs.conf();
c.members[0].host = "127.0.0.1:27017";
rs.reconfig(c);
The above code sample assumes you only have a single replica set node. Make sure you check your config is correct before making any changes