[js] uncaught exception: Error: listDatabases failed

当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

posted @   漫途测开  阅读(312)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示