在使用 Navcat 连接 MongoDB 的时候报错了:

[13][Unauthorized] command listDatabases requires authentication

在这里插入图片描述
但是在测试连接的时候明明是可以的,但是为什么命令行可以连接,但是图形化界面却连接不了了呢?
在这里插入图片描述
Google 后发现原来是需要给 MongoDB 一个验证,需要创建一个用户名和密码。

MacBook:bin zhangyi$ ./mongo
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("28cd3d0c-b45d-47c6-aded-d0d19ee31a35") }
MongoDB server version: 4.4.6
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
	https://community.mongodb.com
> use admin
switched to db admin
> db.createUser({user:"root",pwd:"***",roles:[{role:"root",db:"admin"}]});
uncaught exception: Error: couldn't add user: command createUser requires authentication :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1386:11
@(shell):1:1

通过 use admindb.createUser 来创建一个用户和密码,然后在进行连接就连接成功了。
在这里插入图片描述

在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐