Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Create an additional user

    1. Establish a connection to MongoDB via mongo CLI (see Connect to MongoDB with mongo CLI)

    2. Use db.createUser() to create a new user (see https://docs.mongodb.com/v3.4/reference/method/db.createUser/)

      No Format
      > db.createUser({user: '
    user
    1. TEST_
    name
    1. USER', pwd: '
    user
    1. TEST_
    password
    1. PASSWORD', customData: { name:
    'complete name'
    1.  'NAME OF TESTUSER' }, roles: ['readWriteAnyDatabase']})
      Successfully added user: {
              "user" : "TEST_USER",
              "customData" : {
                      "name" : "NAME OF TESTUSER"
              },
              "roles" : [
                      "readWriteAnyDatabase"
              ]
      }
      >
    2. List users with db.getUsers(

    see https://docs.mongodb.com/v3.4/reference/method/db.createUser/)
    1. ) (see List existing users)

No Format
> db.getUsers()
[
        {
                "_id" : "admin.TEST_USER",
                "user" : "TEST_USER",
                "db" : "admin",
                "customData" : {
                        "name" : "NAME OF TESTUSER"
                },
                "roles" : [
                        {
                                "role" : "readWriteAnyDatabase",
                                "db" : "admin"
                        }
                ]
        },
        {
                "_id" : "admin.bvq",
                "user" : "bvq",
                "db" : "admin",
                "roles" : [
                        {
                                "role" : "root",
                                "db" : "admin"
                        }
                ]
        }
]
>