Running admin commands on secondary mongodb server

You have to let your session know that reading this information from a non-primary server is OK (literally)…

-bash-4.1$ mongo
rs1:SECONDARY> show dbs
2018-02-01T10:37:58.457-0500 E QUERY    [thread1] Error: listDatabases failed:{
        "operationTime" : Timestamp(1517499476, 1),
        "ok" : 0,
        "errmsg" : "not master and slaveOk=false",
        "code" : 13435,
        "codeName" : "NotMasterNoSlaveOk",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1517499476, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:65:1
shellHelper.show@src/mongo/shell/utils.js:813:19
shellHelper@src/mongo/shell/utils.js:703:15
@(shellhelp2):1:1
rs1:SECONDARY> rs.slaveOk()
rs1:SECONDARY> show dbs
admin             0.000GB
config            0.000GB
local             0.001GB
mongoengine_test  0.004GB
rs1:SECONDARY>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.