Home  >  Forum  >  Database
Post New Query

How to create user and password in MongoDB



Asked on September 19, 2019
How to create user and password in MongoDB?


Replied on September 19, 2019
1. Install MongoDB from the URL

2. Go to installation directory /MongoDB/Server/4.0/bin

3. Click on mongod.exe, server will be started.

4. Now click on mongo.exe and a command prompt will open.

5. Write command use <db_name> such as
> use myDB

Database will be created and you will be switched in that database.

6. Now create a user with username userABC and password user123, run the below code in command prompt.

db.createUser(
  {
    user: "userABC",
    pwd: "user123",
    roles: [
       { role: "readWrite", db: "myDB" },
       { role: "read", db: "reporting" }
    ]
  }
)


User will be created successfully.


Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us