当mongo搭建的是replica set集群。
如果你登录某一台SECONDARY节点执行命令 show dbs报错
2022-08-16T15:20:00.606+0800 E QUERY [js] uncaught exception: Error: listDatabases failed:{
"operationTime" : Timestamp(1660634399, 2),
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk",
"$clusterTime" : {
"clusterTime" : Timestamp(1660634399, 2),
"signature" : {
"hash" : BinData(0,"NPF356c5NKl0PqHLlmiQ9vey9e4="),
"keyId" : NumberLong("7101680539345616897")
}
}
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs/<@src/mongo/shell/mongo.js:147:19
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:99:12
shellHelper.show@src/mongo/shell/utils.js:906:13
shellHelper@src/mongo/shell/utils.js:790:15
@(shellhelp2):1:1
是因为SECONDARY节点没有执行show dbs命令的权限。
此时有两种解决方案
1.登录PRIMARY节点
2.使用集群的方式连接
mongo --host testmongo/ip:port,ip:port,ip:port -uusername -p'passwd' --authenticationDatabase admin
[js] uncaught exception: Error: listDatabases failed
最新推荐文章于 2022-10-21 17:01:16 发布