简体   繁体   English

MongoClient.connect - 错误:无法在初始种子列表中找到任何有效的服务器

[英]MongoClient.connect - Error: Could not locate any valid servers in initial seed list

i am trying to connect the mongodb using mongodb.MongoClient.connect() with simple url connection string replicaset. 我正在尝试使用mongodb.MongoClient.connect()与简单的url连接字符串replicaset连接mongodb。 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 这是我的代码,我传递三个mongodb服务器如下


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. 我有三个服务器,一个作为主要,另一个作为辅助。使用rs.status(),我能够看到所有服务器工作正常。但我仍然收到相同的错误。

mongodb version = 2.2.3 mongdb lib version = 1.3.18 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? 你确定你在运行mongod服务器吗? If so, are they running on the default 27017 port (since you did not specify the port number, that would be the default). 如果是这样,它们是否在默认的27017端口上运行(因为您没有指定端口号,这将是默认端口号)。 I would simplify your connection string further and just use 1 server url -- for the sake of debugging. 我会进一步简化你的连接字符串,只使用1个服务器url - 为了调试。 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? 你能从Mongo shell连接它吗? That would be the first test. 这将是第一次测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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