5

I created a default admin user with the following command in mongoshell:

use admin
db.createUser(
  {
    user: "root",
    pwd: "root",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

Then I authenticated using the shell and my credentianls as following: mongo --port 27017 -u "root" -p "root" --authenticationDatabase "admin"

In the shell I am able to see the users and version collections using:

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB
> use admin
switched to db admin
> show tables
system.users
system.version
>

Now when I try to access these tables from MongoDB Compass Community I first authenticate: enter image description here

Now the admin database is showing up empty?

enter image description here

How can I access the users collection and the other collections from the graphic interface just as I did from the shell?

Yassir Khaldi
  • 1,452
  • 1
  • 17
  • 30

2 Answers2

3

The reason why you cannot see the user collection and other collections is the userAdminAnyDatabase built-in role. By default It does not need the necessary rights to read those collections. Try root or dbAdminAnyDatabase depends on your needs.

Cheers,

Resource: https://docs.mongodb.com/manual/reference/built-in-roles/

Bkorb
  • 31
  • 2
0

In short : Use "root" in role instead of "userAdminAnyDatabase" and try again.


If use was set this config in "C:\Program Files\MongoDB\Server\4.4\bin\mongod.cfg"

security: 
   authorization: enabled

You need to comment these 2 line by insert # at start of lines.

Then restart service of "MongoDB Server (MongoDB)".

Open Cmd type these command line by line

mongo
use admin
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])

Then uncomment security and authorization in mongod.cfg and restart service "MongoDB Server (MongoDB)" again.

You can see how to create or update user role in this answer Thanks Dan Dascalescu. https://stackoverflow.com/a/29472184/4418749