Search code examples
mongodbmongodb-replica-set

MongoError: no valid replicaset members found


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);

Solution

  • 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.