DbMongodb - henk52/knowledgesharing GitHub Wiki

MongoDB

Introduction

Purpose

References

Installation

Get warnings and errors from the log file

  • grep -v '"s":"I"' /var/log/mongodb/mongod.log

Creating the admin account

  • mongosh
    • first time there is no challenge
  • use admin
  • db.createUser({"user": "myadmin", "pwd": "mysecret", "roles": ["root"]})
  • exit

if you had accidentally removed the admin user

  • vi /etc/mongod.conf
  • comment out
#security:
#    authorization: "enabled"
  • systemctl restart mongod
  • now you can create a new root/admin user
  • IMPORTANT - remember to re-enable and restart

Various commands

show databases
admin   132.00 KiB
config   60.00 KiB
local    40.00 KiB
db.createUser({
   "user": "gdhpsk",
   "pwd": "123456",
   "roles": ["root"]
})

db.auth("gdhpsk", "123456")

admin> db.createUser({
  user: "admin",
  pwd: "your-password",
  roles: [ { role: "root", db: "admin" } ]
})
use admin
db.system.users.find()

Delete user.

db.dropUser("gdhpsk")
db.adminCommand({ getCmdLineOpts: 1 })