Versions Compared

Key

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

By default there is only 1 user created during the installation process of BVQ (default name: bvq, role: root). You can modify the user & password in the repository installer within the DB access screen.

This user afterwards is used by the BVQ services & UIs to connect to the database. Whenever you change the password of the user remeber to change it in the other BVQ modules (GUI DB connection profile, etc.)

...

Table of Contents

Connect to MongoDB with mongo CLI

  1. Establish a connection to MongoDB via mongo CLI (use CMD or PowerShell)

    No Format
    mongomongosh --authenticationDatabase admin -u bvq -p P@ssw0rd

    (default location of binaries = C:\Program Files\SVA\BVQ\bvq-mongodb\bin, put in PATH variable to access from outside the directory
    change username -u and password -p to your credentials) 

Change the password of an existing user

  1. Establish a connection to MongoDB via mongo CLI (

    use CMD or PowerShell

    see Connect to MongoDB with mongo CLI)

 

...


  1. The user information is configured globally for the entire MongoDB

    in

    within the admin DB, so you have to switch to this DB.
    List existing dbs with show dbs command

    No Format
    PS C:\Users\
    fschenke>
    XXX> mongo --authenticationDatabase admin -u bvq -p P@ssw0rd
    MongoDB shell version v3.4.4
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.4.4
    > show dbs
    admin       0.000GB
    bvq         0.401GB
    local       0.000GB


  2. Mit dem Befehl use admin zur admin DB wechseln:

    Switch to admin db with use admin

    No Format
    > use admin
    switched to db admin


  3. Über das Kommando Use db.changeUserPassword() kann das Passwort des Users geändert werden to change the password for the user logged in (see https://docs.mongodb.com/v3.4/reference/method/db.changeUserPassword/)

    No Format
    db.changeUserPassword("bvq", "NEW_PASSWORD")

    In

    diesem Beispiel wird das Passwort des Users bvq auf NEW_PASSWORD geändert.Nach Ausführung des Befehls wird das PW geändert. Eine Anmeldung ist dann nur mit neuem Passwort möglich.

    this example password is changed to NEW_PASSWORD for user bvq

  4. After executing this command the password will be changed

    No Format
    PS C:\Users\
    fschenke>
    XXX> mongo --authenticationDatabase admin -u bvq -p P@ssw0rd
    MongoDB shell version v3.4.4
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.4.4
    2017-12-05T18:50:07.771+0100 E QUERY    [thread1] Error: Authentication failed. :
    DB.prototype._authOrThrow@src/mongo/shell/db.js:1459:20
    @(auth):6:1
    @(auth):1:2
    exception: login failed
    PS C:\Users\fschenke> mongo --authenticationDatabase admin -u bvq -p NEW_PASSWORD
    MongoDB shell version v3.4.4
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.4.4
    > exit
    bye
    PS C:\Users\
    fschenke>

By default there is only 1 user created during the installation process of BVQ. You can modify the user & password in the repository installer within the DB access screen.

This user afterwards is used by the BVQ services & UIs to connect to the database. Whenever you change the password of the user remeber to change it in the other BVQ modules (GUI DB connection profile, etc.)

  1. XXX>


List existing users

  1. Establish a connection to MongoDB via mongo CLI (use CMD or PowerShell)see Connect to MongoDB with mongo CLI)

  2. Switch to admin db with use admin

    No Format

...

  1. > 

...

  1. use admin
    

...

  1. switched 

...

  1. to 

...

  1. db 

...

  1. admin

(default location of binaries = C:\Program Files\SVA\BVQ\bvq-mongodb\bin, put in PATH variable to access from outside the directory
change username -u and password -p to your credentials)


  1. The user information is configured globally for the entire MongoDB in the admin DB, so you have to switch to this DB.
    List existing dbs with show dbs command

    PS C:\Users\fschenke> mongo --authenticationDatabase admin -u bvq -p P@ssw0rd MongoDB shell version v3.4.4 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.4 > show dbs admin 0.000GB bvq

    Use db.getUsers() to list existing users (see https://docs.mongodb.com/v3.4/reference/method/db.getUsers/)

    No Format
    > db.getUsers()
    [
            {
                    "_id" : "admin.bvq",
                    "user" : "bvq",
                    "db" : "admin",
                    "roles" : [
                            {
                                    "role" : "root",
                                    "db" : "admin"
                            }
                    ]
            }
    ]


Create a user

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

  2. Switch to admin db with use admin

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

    No Format
    > db.createUser({user: 'TEST_USER', pwd: 'TEST_PASSWORD', customData: { name: 'NAME OF TESTUSER' }, roles: ['readWriteAnyDatabase']})
    Successfully added user: {
            "user" : "TEST_USER",
            "customData" : {
                    "name" : "NAME OF TESTUSER"
            },
     
    0.401GB
     
    local
          
    0.000GB
  4. Mit dem Befehl use admin zur admin DB wechseln:

    > use admin
    switched to db admin
  5. Über das Kommando db.changeUserPassword() kann das Passwort des Users geändert werden

    db.changeUserPassword("bvq", "NEW_PASSWORD")

    In diesem Beispiel wird das Passwort des Users bvq auf NEW_PASSWORD geändert.

  6. Nach Ausführung des Befehls wird das PW geändert. Eine Anmeldung ist dann nur mit neuem Passwort möglich.

    PS C:\Users\fschenke> mongo --authenticationDatabase admin -u bvq -p P@ssw0rd MongoDB shell version v3.4.4 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.4 2017-12-05T18:50:07.771+0100 E QUERY [thread1] Error: Authentication failed. : DB.prototype._authOrThrow@src/mongo/shell/db.js:1459:20 @(auth):6:1 @(auth):1:2 exception: login failed PS C:\Users\fschenke> mongo --authenticationDatabase admin -u bvq -p NEW_PASSWORD MongoDB shell version v3.4.4 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.4 > exit bye PS C:\Users\fschenke>
    "roles" : [
                    "readWriteAnyDatabase"
            ]
    }
    >

    (see https://docs.mongodb.com/v3.4/core/security-built-in-roles/ for available roles in MongoDB)


  7. List users with db.getUsers() (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"
                            }
                    ]
            }
    ]
    >


Remove a user

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

  2. Switch to admin db with use admin

  3. Use db.dropUser() to delete an existing user (see https://docs.mongodb.com/v3.4/reference/method/db.dropUser/)

    No Format
    > db.dropUser('TEST_USER')
    true
    >


  4. List users with db.getUsers() (see List existing users)

    No Format
    > db.getUsers()
    [
            {
                    "_id" : "admin.bvq",
                    "user" : "bvq",
                    "db" : "admin",
                    "roles" : [
                            {
                                    "role" : "root",
                                    "db" : "admin"
                            }
                    ]
            }
    ]
    >

    User TEST_USER was deleted successfully (user was created in Create an additional user)