Node.js MongoDB on Ubuntu: no valid settlement servers listed

I am trying to connect to a replica set from Ubuntu using this:

return when.promise(function(resolve,reject){ new MongoClient().connect(url, {replSet: options }, function(err, db){ console.dir(err) if (err) reject(err); resolve(db); }); }); 

The URL is as follows:

'mongodb://mongo1.mysite.com:36108,mongo2.mysite.com:36108,mongo3.mysite.com:36108/db_config?w=0'

I connect to several databases and intermittently see this error:

{ name: 'MongoError', message: 'no valid seed servers in list' }

And crash node.js.

I was a little lost at this moment. And the main problem is that it works fine on MAC, and I see this problem only on Ubuntu. I am on the latest mongo driver for node.js

UPDATE

I looked at the native driver source:

http://mongodb.imtqy.com/node-mongodb-native/core/api/replset.js.html

and found that this error was caused by this condition (line 987): state.initialConnectionServers == 0 && state.replState.state == CONNECTING)

I don’t know why this is happening.

+5
source share
3 answers

Increasing the number of file descriptors solved the problem.

Ubuntu 12.04.5 LTS defaults to 1024, which is not enough.

+1
source

The difference is that you do not have a replica set on your own single computer (osx?) For laptop / desktop. his work offline. but have or intend to have a set of replicas on these three servers.

here are some potential problems with the provided string.

1) 27017 is the default port for mongo, so if it has not been specifically changed to 36108, this is not true.

 mongodb://mongo1.mysite.com:36108,mongo2.mysite.com:36108,mongo3.mysite.com:36108/db_config?w=0 

try

 mongodb://mongo1.mysite.com:27017,mongo2.mysite.com:27017,mongo3.mysite.com:27017/db_config?w=0 

2) w = 0 is unfamiliar to me, maybe this is the name of your replica set. usually the connection string for replica sets is as follows, where rs0 is the name of replicaSet.

 mongodb://mongo1.mysite.com:27017,mongo2.mysite.com:27017,mongo3.mysite.com:27017/replicaSet=rs0 

3) it is possible that you do not have a customized set of replicas. check rs.config

log in to the server, mongo1.mysite.com

go to mongo shell using mongo admin -u clusteradmin -p whateverpassword

a type

rs.config ()

If you do not see anything like this, then you do not have a replica to connect to. here rs0 is the name of the replica set. your MAY be called w ???

 { "_id" : "rs0", "version" : 4, "members" : [ { "_id" : 0, "host" : "mongo1.mysite.com:36108" }, { "_id" : 1, "host" : "mongo2.mysite.com:36108" }, { "_id" : 2, "host" : "mongo3.mysite.com:36108", } ] } 
  1. If this configuration is missing, you need to add your 3 hosts to the replica set configuration.

rs.add ("mongo1.mysite.com:36108") // or the default port with "mongo1.mysite.com:27017" rs.add ("mongo2.mysite.com:36108") rs.add ("mongo3 .mysite.com: 36108 ")

But better than anything, it's a replica set, including this doc for converting a standalone replica set

This line / db _config looks like the equivalent rs.config () command, but it does http and expects the server list to be added to the replica set. but honestly you can't connect to a replica set to configure it? so it seems strange. you can connect to the primary, so try

 mongodb://mongo1.mysite.com:36108/db_config?w=mongo1.mysite.com:36108,mongo2.mysite.com:36108,mongo3.mysite.com:36108 
+2
source

Please follow the solutions given by rinchnik and Gabe's rainbow . And if the problem still persists, upgrade the mongodb modules to version 2.2.27+ and mongoose to version 4.9.1+.

0
source

Source: https://habr.com/ru/post/1207952/


All Articles