List users using MongoDB Ruby Driver

Hi I have been using “MongoDB Ruby Driver” which you can find more information about here GitHub - mongodb/mongo-ruby-driver: The Official MongoDB Ruby Driver.

I am trying get a list of users using the code example “client.database.users” from

However I end up with a “Mongo::Auth::User::View” class as a return.
There is no document about what “Mongo::Auth::User::View” is and how to use it to get list of users. I can add, edit. update, and delete user however I can not get a lost if users to display.

There is no getUsers or getRoles methods.
To make this short how can I use “MongoDB Ruby Driver” to get a list of users for a database? This has been my final struggle.

If any one know how to to do this in ruby it will be greatly appreciated. It can be different gem I wouldn’t mind switching as long as its ruby.

Thank you.

Hello @Saimon_Lovell, welcome to the community.

The command to run is the usersInfo. The db.getUsers() is a wraper around the usersInfo command.

These commands return information about one or more users.

In Ruby, you can use the command method, to execute the usersInfo command on the database to get the list of users.


Thank you very much. You have made my day. I was loosing it looking for it all over the web lol.

client.database.command(usersInfo: 1)
client.use(:admin).database.command(usersInfo: 1)

That did the trick. Thanks again.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.