ubuntu Mongodb clinets 链接失败的问题

之前就是直接

sudo apt install mongodb-clients

结果 在链接MongoDB的时候报错

ubuntu@ts:~$ sudo mongo --host hostip:27017 -u "username" -p "password" --authenticationDatabase "dbname"
MongoDB shell version: 2.6.10
connecting to: hostip:27017/test
2018-11-16T17:02:49.222+0900 Error: 2 { ok: 0.0, errmsg: "Auth mechanism not specified", code: 2, codeName: "BadValue" } at src/mongo/shell/db.js:1287
exception: login failed

后来查了一下host 的 MongoDB server 版本是v4.0.3,由此猜测是版本问题 导致不能连接成功

解决方案

在终端上输入如下命令:

删除 之前的 mongodb-clients

sudo apt-get purge mongodb-clients

在这里索性直接安装了整个 MongoDB

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

这样再试着链接 host

ubuntu@ts:~$ sudo mongo --host hostip:27017 -u "username" -p "password" --authenticationDatabase "dbname"
MongoDB shell version v4.0.4
connecting to: mongodb://hostip:27017/
Implicit session: session { "id" : UUID("044ce961-2b80-45c9-8d79-aeeb758ab5a8") }
MongoDB server version: 4.0.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
>

由此可见 现在的MongoDB clients 版本是 V4.0.4

 

你可能感兴趣的:(工作整理)