DS
Создаем пользвателся в базе admin, с правами на базу test
> use admin
switched to db admin
> db.createUser({ user: "test", pwd: "test", roles: [{role: "readWrite", db: "test"}]})
Successfully added user: {
"user" : "test",
"roles" : [
{
"role" : "readWrite",
"db" : "test"
}
]
}
>
Заходим в базу тест, убеждаемся что там пользователся нет:
>
use testДелаем запрос от пользователя test в базу test
switched to db test
> db.getUsers()
[ ]
root@test2:~# mongo --norc -utest -ptest --authenticationDatabase admin --eval 'db.getCollectionNames()' test
MongoDB shell version v3.6.18
connecting to: mongodb://127.0.0.1:27017/test?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("66821ec0-2b47-4bdc-a4b1-143031d15d17") }
MongoDB server version: 3.6.18
[
"collection_test",
"incr",
"incr2",
"incr3",
"incr4",
"t1",
"t2",
"test"
]
