2

Can anyone explain in what scenario the below error occurs?

database error { 
[MongoError: no valid replicaset members found]
name: 'MongoError',
message: 'no valid replicaset members found' 
} 

This is how I connect to the replica set:

var url = format("mongodb://%s:%s@%s/%s?authSource=%s&replicaSet=%s&re‌​adPreference=%s&read‌​PreferenceTags=%s&co‌​nnectTimeoutMS=%s&so‌​cketTimeoutMS=%s", username, pswd, replicationSet, db, authdb, replicaSetName, readPreference, readPreferenceTags, 5000, 5000);
var db = mongojs(url);
Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
  • Hi Prabhu Kathiresan - are you getting this error? If so, can you show us how you are connecting to the replica set? – Vince Bowdren Oct 11 '16 at 10:36
  • var url = format("mongodb://%s:%s@%s/%s?authSource=%s&replicaSet=%s&readPreference=%s&readPreferenceTags=%s&connectTimeoutMS=%s&socketTimeoutMS=%s", username, pswd, replicationSet, db, authdb, replicaSetName, readPreference, readPreferenceTags, 5000, 5000); var db = mongojs(url); This is how I connect with replica set – Prabhu Kathiresan Oct 14 '16 at 13:20
  • got anything on this ?? – Sudhanshu Gaur Dec 06 '16 at 19:55
  • It seems like it is a driver issue: https://github.com/strongloop/loopback-connector-mongodb/issues/319 – brasskazoo Mar 27 '17 at 09:34

2 Answers2

0

In the situation where there is no secondaries what are "up-to-date" comparing to primary. There is changes on primary what secondaries has not replicated yet. If client is writing constantly (to primary), it cannot step down.

Of course also in the situation where there is minority of nodes up in the replica set. Like one of three nodes.

So.. In the replica set, you must always have majority of voting members up and running. (2/3, 3/4, 3/5,...)

Can you connect that RS's primary node directly from command line with 'mongo' command? If yes and you application cannot, then there is error at your app's connection string.

If your RS don't have 'primary', check (different) nodes mongodb.log file for error messages what explains what is wrong.

JJussi
  • 1,540
  • 12
  • 12
0

This message can appear although there are valid replicaset members available if you're using a deprecated version of the mongodb driver as mentionned in https://github.com/strongloop/loopback-connector-mongodb/issues/319 (thanks brasskazoo for pointing it out). You should check your version and upgrade if necessary.

In the meantime, reconfiguring your replica set may bring all members of the replicaset back up and temporarily fix the situation. The command is rs.reconfig() as documented in https://docs.mongodb.com/manual/reference/method/rs.reconfig/

Aymeric Bouzy aybbyk
  • 2,031
  • 2
  • 21
  • 29