MongoDB从节点支持读请求
因为mongo的原生特性,从节点默认只做故障切换功能,不提供读的请求。正常情况下在从节点读请求会显示:
---
wanya:SECONDARY> show dbs
2020-09-27T13:36:43.126+0800 E QUERY [js] Error: listDatabases failed:{
"operationTime" : Timestamp(1601185003, 2),
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk",
"$clusterTime" : {
"clusterTime" : Timestamp(1601185003, 2),
"signature" : {
"hash" : BinData(0,"8baIHeEIJCzjugfNfZljMcxLf1k="),
"keyId" : NumberLong("6842713381699321872")
}
}
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:139:1
shellHelper.show@src/mongo/shell/utils.js:882:13
shellHelper@src/mongo/shell/utils.js:766:15
@(shellhelp2):1:1
---
not master and slaveOk=false 从这句话可以看出从节点目前的配置不支持读请求,可以通过
rs.slaveOk();来支持读。