3

I have 22 databases on a single MongoDB instance. I came across root role of MongoDB authentication. I want to create a single user which can do anything to existing database as well as create new database and manage them fully. I ran the following command but it doesn't allow me to access any database except admin.

use admin
db.createUser(
{
    user: "iamroot",
    pwd: "<pa$$w0rd>",
    roles: [ "root" ]
})

It only stores root role for admin database only. How can I apply root role to all existing database as well as on new database if added? Is there only one way to supply all the DB name in roles array like this to achieve what I want?

use admin
db.createUser(
{
    user: "iamroot",
    pwd: "<pa$$w0rd>",
    roles: [ 
        { role: "root", db: "db_1" },
        { role: "root", db: "db_2" },
        { role: "root", db: "db_n" },
    ]
})
Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115

1 Answers1

0

You would need to assign root for admin db explicitly I guess. For me the following worked (am on version: 3.4.23):

use admin
db.createUser(
{
    user: "iamroot",
    pwd: "<pa$$w0rd>",
    roles: [ 
        { role: "root", db: "admin" }
    ]
})
maicalal
  • 101
  • 1
  • 8