问题
在连接MongoDB的时候出现如下错误:
$ mongo xxx -u <user> -p <passwd>
MongoDB shell version: 2.6.5
connecting to: xxxx
.
.
.
2021-03-12T17:04:17.867+0800 warning: No primary detected for set
2021-03-12T17:04:17.867+0800 All nodes for set are down. This has happened for 1 checks in a row. Polling will stop after 29 more failed checks
2021-03-12T17:04:17.868+0800 Error: connect failed to replica set xxx:xxx at src/mongo/shell/mongo.js:148
exception: connect failed
这个一般原因都是因为mongodb clinet的版本太低,需要安装新版的MongoDB client
安装新版client
mongodb的源地址为:https://repo.mongodb.org/ 需要根据自己的系统版本,找到对应的路径下的包链接信息。
我的系统为 CentOS 7
,架构为 x86_64
,那我们就可以去 https://repo.mongodb.org/yum/redhat/7/mongodb-org/ 下的对应版本的 x86_64 路径下下载,我下载最新 4.4.4 版本的客户端,其链接为:https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-shell-4.4.4-1.el7.x86_64.rpm
如果系统为 Ubuntu
或者 Debain
则可以去 https://repo.mongodb.org/apt/ 路径下寻找对应的包
$ wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-shell-4.4.4-1.el7.x86_64.rpm
$ yum install -y ./mongodb-org-shell-4.4.4-1.el7.x86_64.rpm