How can we get list of users in mongodb ?

85 views
Skip to first unread message

Sharmila

unread,
Apr 25, 2019, 7:50:01 AM4/25/19
to mongodb-user
Hello ,

Am aware that  db.getUsers() can show all users in current database in mongodb, but how to list all users in all databases for ease of management as an administrator? I have tried to check if there is any collection under "admin" database where it contains users authentication and authorization but it has none. Please note that this is test environment but i have created users in admin database. Not sure why "system.users " collection is not showing up under "admin" database.


Also,how can we check how many users are logged in currently ?


Thanks in advance!

Regards,
Sharmila

Kevin Adistambha

unread,
May 7, 2019, 3:08:09 AM5/7/19
to mongodb-user

Hi Sharmila,

Not sure why “system.users “ collection is not showing up under “admin” database.

This was actually a known issue that is being addressed in SERVER-38867.

You can list all users in all databases by using a script in the mongo shell, for example:

Mongo().getDBNames().forEach( x => { Mongo().getDB(x).getCollection('system.users').find().forEach(printjson) })

Also,how can we check how many users are logged in currently

I don’t believe there’s a function to list the number of logged in users. However, you can check the current number of connections to the server using the db.serverStatus().connections command, the output of which is explained in the serverStatus page

Best regards,
Kevin

Sharmila

unread,
May 7, 2019, 3:19:49 AM5/7/19
to mongod...@googlegroups.com

Hi Kevin,

Thanks for your reply. Will check the command db.serverStatus().connections to see the connections. Based on the number of connections listed in the output, i guess i can check how many users are logged in currently. Correct me if i am wrong.

Also, I am using db.system.users.find() to list all the users created

Thanks,
Sharmila

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/PcjFqSGYH9s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/44465b45-bdbc-4bff-9d4e-2c58148469bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Sharmila
Reply all
Reply to author
Forward
0 new messages