mongoDB - The database for modern applications

mail

How to create administrator / standard user accounts ?

Administrator user account (source) :

  1. start the mongoDB shell :
    mongo
    Percona Server for MongoDB shell version v4.0.12-6
    connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
    Implicit session: session { "id" : UUID("1beaa175-c573-4181-80da-d91c241e05f1") }
    Percona Server for MongoDB server version: v4.0.12-6
  2. select the database to alter :
    use admin
    switched to db admin
  3. create the administrator account :
    The name given to this account doesn't matter as long as it has the root role.
    db.createUser({
    	user: "root",
    	pwd: "12345687",
    	roles: [ "root" ]
    })
    Successfully added user: { "user" : "root", "roles" : [ "root" ] }
  4. exit
    bye

Standard user account :

  1. start the mongoDB shell
  2. select the database to alter :
    use myMongodbDb
    switched to db myMongodbDb
  3. create the user account :
    db.createUser({
    	user: "bob",
    	pwd: "password",
    	roles: [{ role: "readWrite", db: "myMongodbDb" }]
    })
    Successfully added user: {
    	"user" : "bob",
    	"roles" : [
    		{
    			"role" : "readWrite",
    			"db" : "myMongodbDb"
    		}
    	]
    }
  4. exit
    bye
mail

Notes on mongoDB

Main configuration file :

Default configuration file on Linux systems : /etc/mongod.conf

systemd settings :

find /lib/systemd/ -name "*mongo*"
	/lib/systemd/system/mongod.service

systemctl show mongod.service