通过admin 用户登录mongo
[root@bogon bin]# ./mongo mongodb://admin:123456@localhost/admin
MongoDB shell version v4.0.3
connecting to: mongodb://localhost/admin
Implicit session: session { "id" : UUID("e7edb90f-d0dd-4d9e-8955-e3c27b301dfa") }
MongoDB server version: 4.0.3
创建数据库card
> use card
switched to db card
查看当前db
> db
card
查看所有db
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
发现没有card
这是因为没有插入数据。
接下来创建用户
> db.createUser({user:'pl-card',pwd:'123456',roles:['readWrite']})
Successfully added user: { "user" : "pl-card", "roles" : [ "readWrite" ] }
认证用户
> db.auth('pl-card','123456')
1
再查看数据库却报错 登录用户过多
> show dbs
2019-01-25T00:48:36.797+0800 E QUERY [js] Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "too many users are authenticated",
"code" : 13,
"codeName" : "Unauthorized"
} :
ctrl c 退出 ,重新用新用户登录
./mongo mongodb://pl-card:123456@localhost/card
MongoDB shell version v4.0.3
connecting to: mongodb://localhost/card
Implicit session: session { "id" : UUID("2ee5f767-10c9-4803-b8bb-fcb46386b459") }
MongoDB server version: 4.0.3
创建集合
> db.createCollection("aaa")
{ "ok" : 1 }
>
通过工具链接后查看结果
image.png
ok 这就成功了。
网友评论