参考链接: https://www.cnblogs.com/highsea90/p/4512019.html
默认你已经为admin数据库创建好用户、设置好密码
在shell窗口输入错误命令,连接不上
mongo -u错误用户名 -p错误密码127.0.0.1:27017/admin
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
在shell窗口输入正确命令,连接上了
mongo -u正确用户名 -p正确密码127.0.0.1:27017/admin
顺利操作
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
test1 0.000GB
test3 0.000GB
> use admin
switched to db admin
> show collections
system.users
system.version
> exit
bye