Search code examples
mongodbmongodump

MongoDB. Newly added replicaset members can't show databases


I have a Replicaset running with 1 primary and 4 secondaries. The newly added two secondaries give me an error on the show databases command.

replicaset:SECONDARY> use admin

switched to db admin

replicaset:SECONDARY> show databases

listDatabases failed:{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not > master" } at src/mongo/shell/mongo.js:47

rs.status() all are ok for the secondaries. Health 1, state 2.

rs.conf() has (except for host/port off course) a difference:

Using command on older secondaries only gives back the: _id, host and priority.

The newer secondaries have: _id, host, arbiterOnly, buildIndexes, hidden, priority, tags, slaveDelay, votes and a whole settings node with: chainingAllowed, heartbeatTimeoutSecs, getLastErrorModes, getLastErrorDefaults. Weird, because the members were added in the same manner using rs.add(host:port).

db.version(): - Older Secondaries and Primary: 2.6.5 - Newer Secondaries: 3.0.6

The other two (older) secondaries have no problem at all with the Show Databases command. It seems to be related to the newer 3.0.6 version. Using db.SlaveOK helps on 3.0.6. , but cannot given as parameter using the mongodump.exe.

Any idea how I can use the Show Databases command by default on Secondaries?


Solution

  • This is a normal behaviour.

    As per manual you need to execute

    rs.slaveOk()
    

    which provides a shorthand for the following operation:

    db.getMongo().setSlaveOk()

    This allows the current connection to allow read operations to run on secondary members. See the readPref() method for more fine-grained control over read preference in the mongo shell.