Hi everyone,
I have setup a shared cluster and now creating a user for a particular db with readWrite permission. What I also want this user can do is, he can create collections, enableSharding, shardCollection but can not delete the collection/db.
I could not find any Built-In-role for this exact purpose. I mean I can give root access to that user, but then he will have access to all the databases which I dont want.
I tried creating a user from admin db and credentials but failed. For example, my db is demo and collection is users
So I created role my-user-role with enableSharding and shardCollection actions which can only access demo db (not sure if this is correct) .
use admin
db.createRole(
{
role: "my-user-role",
privileges: [
{ resource: { cluster: true }, actions: [ "enableSharding", "shardCollection" ] }
],
roles: [
{ role: "readWrite", db: "demo" }
]
}
)
the role is created, next I want to create a new user (who only has access to demo db) and assign this role to that user:
use admin
db.createUser({
user: 'demo-db-user',
pwd: 'somepwd',
roles: [
{
role: 'my-user-role', db: 'demo'
}
]
})
But I get error like this:
MongoServerError: Could not find role: my-user-role@demo
I assume, I can not have a user with cluster permission on a db? What is the best way to achive this then?