Evanss
Evanss

Reputation: 23593

See / setup a user with MongoDB Compass?

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

Upvotes: 32

Views: 42319

Answers (4)

joe
joe

Reputation: 5542

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

And then paste this:

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.

Upvotes: 5

Fredric Cliver
Fredric Cliver

Reputation: 195

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

Upvotes: 1

MauriRamone
MauriRamone

Reputation: 503

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

Upvotes: 2

Evanss
Evanss

Reputation: 23593

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.

Upvotes: 34

Related Questions