How to configure Mongodb authentication

22 Feb 2021

blog details

How to configure Mongodb authentication

By: RSDigitech | Published At : 22 Feb 2021    


MONGO DB CONFIGURATION


Step1:

Download the mongo db from the link

 https://www.mongodb.com/try/download/community


donwload mongodb

 

After the successful download, install the mongodb.

 successfully downlaod and install

 

 “Agree” to the terms and conditions.

 “Agree” to the terms and conditions.

 Click on complete and Next

 Click on complete and Next

 Leave it as MongoDb Service.

Leave it as MongoDb Service.

 

 Proceed to next and wait till the installation complete.

Proceed to next and wait till the installation complete.

 Final installation

 Final installation


Step2:

 After Installation the mongo files are created in

“C:\Program Files\MongoDB\Server\4.4\bin“

 After Installation the mongo files are created in

Step3:

 Open “CMD ” in the same folder where the mongo files are created.

Open “CMD ” in the same folder where the mongo files are created.


Step4:

Run “mongod ” command to start the server

Run “mongod ” command to start the server

Step5:

Create folder as data/db in the C: drive

 Create folder as data/db in the C: drive

 

Then try the “mongod ” command again

 Server starts running.

Server starts running

 Step6:

 Set it as environment Variable “C:\Program Files\MongoDB\Server\4.4\bin“

 

Set it as environment Variable “C:\Program Files\MongoDB\Server\4.4\bin“

Set it as environment Variable “C:\Program Files\MongoDB\Server\4.4\bin“ 2

 Run “mongodb ”

 Run “mongodb ”

 

 Step7:

Try to connect with mongodb compass.

 

Try to connect with mongodb compass.

 Get Connected to mongodb

 Get Connected to mongodb



MONGO DB AUTHENTICATION

Step1:

Run Mongodb Server

Run Mongodb Server


Step2:

 Run mongo client in terminal.

 Run mongo client in terminal.


Step3: Create User for admin authentication

 “Use admin” command to switch to admin db.

“Use admin” command to switch to admin db.

 

 

Step 4:

 For creating user use the following command.

 db.createUser(

 {

   user: "superuser",

   pwd: "changeMeToAStrongPassword",

   roles: [ "root" ]

 }

)

 For creating user use the following command

 

Step 5:

 “Show users” lists the users for db.

 “Show users” lists the users for db

 

 Step6:

 Shutdown the server and restart with auth. “db.shutdownServer()”

 Shutdown the server and restart with auth. “db.shutdownServer()”

 

 Step7:

 Run the server with authentication “mongod --auth

 Run the server with authentication “mongod --auth”


Step8:

 Connect client with authentication credentials

 Connect client with authentication credentials

 

 

Connect client with authentication credentials 2

 

Connect client with authentication credentials 3

 

Now able to fetch datas..

 Now able to fetch datas..

 

    

Technologywe use

  • PHP
  • Angular
  • Android
  • Laravel
  • Salesforce
  • Tibco
  • Mulesoft