Answers for "add user name and password for mongodb"

1

connect to mongodb with username and password

->First run mongoDB on terminal using
mongod

->now run mongo shell use following commands

    use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

->Re-start the MongoDB instance with access control.
mongod --auth

->Now authenticate yourself from the command line using
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"

->You can read it from
https://docs.mongodb.com/manual/tutorial/enable-authentication/
Posted by: Guest on April-13-2021
0

mongodb create database with username and password

use mydb
db.createUser(
   {
     user: "myuser",
     pwd: "mypassword",
     roles: [ "dbOwner" ]
   }
)
Posted by: Guest on September-04-2021

Code answers related to "add user name and password for mongodb"

Browse Popular Code Answers by Language