Create Role Username Password Mongodb

Yup secara default mongodb tidak menggunakan username dan password. Lalu bagaimana jika menginginkan mongodb diberikan password ?
Sekarang ikuti tahapan dibawah ini dengan mengetikan perbaris : 
  • mongod
  • use admin
  • show collections
  • db.createUser({ user : “root”, pwd : “madun2015”, roles : [“userAdminAnyDatabase”]})

Output : Successfully added user: { “user” : “root”, “roles” : [ “userAdminAnyDatabase” ] }

  • show collections

Output :

  • system.users
  • system.version
  • db.system.users.find()

Output :
{ “_id” : “admin.root”, “user” : “root”, “db” : “admin”, “credentials” : { “SCRAM-SHA-1” : { “iterationCount” : 10000, “salt” : “v1tliLcEqIeIeW6QFQu2cA==”, “storedKey” : “1oxK7PBo4u3oadBzHtpmrTp+qic=”, “serverKey” : “dsk5i0Ky7e7WFPCKkpyeF7aDSw8=” } }, “roles” : [ { “role” : “userAdminAnyDatabase”, “db” : “admin” } ] }

Selesai

Leave a Reply

Your email address will not be published. Required fields are marked *