30

With MongoDB Compass is it possible to see users for a database or create new ones?

Evanss
  • 23,390
  • 94
  • 282
  • 505

4 Answers4

31

Ive managed it on the command line with:

mongo
use (my database name)
db.createUser( { user: "myuser", pwd: "password", roles: ["readWrite"] })

However I would still much prefer a GUI to do this.

Evanss
  • 23,390
  • 94
  • 282
  • 505
3

If you're trying to create a new DB with a user that "owns" that DB (i.e. has read/write and admin commands for that DB), here's how to do that using only MongoDB Compass:

  1. Open up MongoDB Compass and connect with your admin user.
  2. Create a new DB with the "+" button at bottom of the DB list.
  3. Click the MONGOSH shelf/tab at the bottom of the screen and paste this:
use NAME_OF_NEW_DB

db.createUser(
  {
    user: "NAME_OF_NEW_USER",
    pwd: "NEW_USER_PASSWORD",
    roles: [ { role: "dbOwner", db: "NAME_OF_NEW_DB" } ]
  }
)

Other roles are explained in the MongoDB docs.

joe
  • 3,752
  • 1
  • 32
  • 41
2

No, it isn't (at least until version 1.20.4 of Compass)

MauriRamone
  • 469
  • 1
  • 3
  • 21
1

If I run a command in CLI after made up a user. I can see that by using this command.

db.system.users.find().pretty()
{
        "_id" : "admin.admin",
        "userId" : UUID("****"),
        "user" : "admin",
        "db" : "admin",
        "credentials" : {
                "SCRAM-SHA-1" : {
                        "iterationCount" : 10000,
                        "salt" : "***",
                        "storedKey" : "***",
                        "serverKey" : "***"
                },
                "SCRAM-SHA-256" : {
                        "iterationCount" : 15000,
                        "salt" : "***",
                        "storedKey" : "***",
                        "serverKey" : "***"
                }
        },
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                }
        ]

But I can't see the 'system.users' collection in the Compass client. I think, the Compass does not support this the listing and creating user features.

But, if you use other client (eg. TablePlus), You can see those hidden documents

Fredric Cliver
  • 175
  • 1
  • 1
  • 9