1

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.

Soorya Prakash
  • 921
  • 3
  • 9
  • 29

1 Answers1

3

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.

alernerdev
  • 2,014
  • 3
  • 19
  • 35
  • when i am trying to use the single server , it was working fine , but more then one causing the error. I haven't done any replica set configuration between the servers , am i want to do it? since the ports are default port "27017" i haven't added in the string – Soorya Prakash Nov 20 '14 at 13:36
  • 2
    If you haven't configured a replica set, then you have servers that are completely different independent of each other -- they are both primary. I don't think you can connect to multiple primary servers,doesn't make sense. So either stick with one server, or make a real replica set – alernerdev Nov 21 '14 at 01:49