Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I query users created in $external database

I'm trying to configure certificate based mongo authentication, generally it works fine but there's one question I cannot find answer for. Suppose I created a user in $external database:

use $external
db.createUser({user: "[email protected],CN=jsmith,OU=Mongo Admins,O=Initech,C=US",
               roles: [{"role" : "root","db" : "admin"}]
})

Q: How can I query the content of $external database, particularly users data?

Is there any similar way to:

use admin
db.system.users.find()
like image 844
wilu Avatar asked Dec 19 '22 05:12

wilu


1 Answers

The "$external" database isn't a real database, and it contains no data. All users and roles data for all databases is stored in admin.system.users or admin.system.roles.

The preferred solution is to use the getUsers command.

In the shell, you would issue the following statements:

use $external
db.getUsers()

If you have the right privileges, you can also query admin.system.users to find the users for any database, as follows:

use admin
db.system.users.find({db: "$external"})
like image 130
Andy S Avatar answered Jan 06 '23 07:01

Andy S