i am trying to connect the mongodb using mongodb.MongoClient.connect() with simple url connection string replicaset. When i start the server its throwing the error as
this is my code where i am passing three mongodb server as follows
var MongoClient = mongodb.MongoClient; MongoClient.connect('mongodb://192.168.0.16,192.168.0.23,192.168.0.17/test', function(err, db) { if(err){ console.error("Error! Exiting... Must start MongoDB first"); console.log("The error is :::::::::::::::", err); process.exit(1); }else{ console.log("Connection successful"); } });
mongodb version = 2.2.3 mongdb lib version = 1.3.18
{ "set" : "rs01", "date" : ISODate("2015-01-09T07:35:15Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "192.168.0.23:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 2079, "optime" : Timestamp(1420787077000, 1), "optimeDate" : ISODate("2015-01-09T07:04:37Z"), "lastHeartbeat" : ISODate("2015-01-09T07:35:13Z"), "pingMs" : 0 }, { "_id" : 1, "name" : "192.168.0.16:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 2088, "optime" : Timestamp(1420787077000, 1), "optimeDate" : ISODate("2015-01-09T07:04:37Z"), "self" : true }, { "_id" : 2, "name" : "192.168.0.17:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 1838, "optime" : Timestamp(1420787077000, 1), "optimeDate" : ISODate("2015-01-09T07:04:37Z"), "lastHeartbeat" : ISODate("2015-01-09T07:35:14Z"), "pingMs" : 0 } ], "ok" : 1 }
But i don't know what could be a issue.This issue was occurring in my production setup also.
Well, looks straight forward. Are you sure you are running the mongod servers? If so, are they running on the default 27017 port (since you did not specify the port number, that would be the default). I would simplify your connection string further and just use 1 server url -- for the sake of debugging. I would also explicitly specify a port number to spell it all out. Is one of these servers a primary? Can you connect to it from Mongo shell? That would be the first test.
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.