0% found this document useful (0 votes)
8 views5 pages

Mon God B Authentication

The document outlines the concepts of authentication and authorization in MongoDB, detailing how to enable authentication by modifying the configuration file and restarting the service. It provides instructions for creating an admin user with specific roles and how to log in and out of the database. Additionally, it lists various roles available in MongoDB and explains how to check the current logged-in user.

Uploaded by

INSTA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Mon God B Authentication

The document outlines the concepts of authentication and authorization in MongoDB, detailing how to enable authentication by modifying the configuration file and restarting the service. It provides instructions for creating an admin user with specific roles and how to log in and out of the database. Additionally, it lists various roles available in MongoDB and explains how to check the current logged-in user.

Uploaded by

INSTA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Authentication And Authorization

Authentication – who can access it


Authorization – what operation can be performed

Enabling authentication in MongoDB involves making


configuration changes

OPEN :

C:\Program Files\MongoDB\Server\8.0\bin\mongod.cfg

Add :

Security :
authorization : enabled

Now restart MongoDB service from services or win +


R and type services.msc
Now can’t show dbs :
Only use admin database no any other.
We’ll create user in admin :
db.createUser({
user : "adminUser",
pwd : "password",
roles :["userAdminAnyDatabase","dbAdminAnyDatabase"]
All rights
})
Login via :
db.auth(‘uName’,’uPwd’)

Logout :
Db.logout()

ROLES :

read dbAdmin readAnyDatabase


readWrite userAdmin reaWriteAnyDatabase
dbOwner
userAdminAnyDatabase
dbAdminAnyDatabase

clusterManager clusterAdmin
clusterMonitor hostManager
userAdmin root backup restore

Both user is created in admin db so rights also in only


admin db

Let’s check :

First logout then ctrl + c

Inside mongosh we can login via : db.auth()


But outside mongosh we can use :
Mongo –authenticationDatabase dbName -u username -
p password
(Not working)

How to know current loggedin user :

You might also like