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
Error: Could not locate any valid servers in initial seed list
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");
}
});
I have done replica set also. I have three servers one act as a primary and other act as secondary.Using rs.status(), i can able to see that all server working fine.But still i receiving the same error.
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.