How to run Authentication on Mongodb



Step by step run  Authentication on Mongodb
  1. start mongod.exe  ( mongodb server)

  2. start mongo.exe (mongodb shell)

  3. set name db = admin
    > use admin

  4. create user  supperadmin
    > db.createUser(
    {
  5.     user: "supperadmin",
        pwd: "password",
        roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
      }
    )
       you can change permission  by your self  at  role "permission", db: "dbname"

    Ex
    roles: [ { role: "readWriteAnyDatabase", db: "admin" } ]
     or
        user: "myTester",
        pwd: "xyz123",
        roles: [ { role: "readWrite", db: "test" },
                 { role: "read", db: "reporting" } ]


    if success system will show like a below picture


  6. Test Authentication
    > db.auth("supperadmin","password")


  7. close  ( mongodb server)
  8. open mongodb server by command
    mongod  --auth

  9. try  reconnect mongodb server

    mongo admin -u "supperadmin" -p "password"





     







Comments

Popular Posts