Listing Users
User accounts are stored in the db.system.users
collection of each database. The User
object contains _id
, user
, pwd
, roles
, and sometimes otherDBRoles
fields. There are a couple different ways to get a list of user objects. The first is to change the database to the one you want to list users on and then execute the show users
command. The following example changes to the admin
database and lists users as shown in Figure 12.3:
use adminshow users
You can also use a query such as find
on the db.system.users
collection. However, db.system.users.find()
returns a cursor object that you ...
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.