Mongodb Change User Password

By Yashwant Chavan, Views 1422, Date 10-Oct-2016

In this tutorial we will learn how to Change User Password using mongodb db.changeUserPassword() method.

tags mongodb

Mongodb Change Password - db.changeUserPassword()

Updates the user’s password. Refer following changeUserPassword() method syntax.

db.changeUserPassword(username, password);

username - string specifies name of the user for which you are updating the password.

password - string specifies the corresponding password.

Shell command output

> use technicalkeeda
switched to db technicalkeeda

> db.getUsers()
[
        {
                "_id" : "technicalkeeda.Yashwant",
                "user" : "Yashwant",
                "db" : "technicalkeeda",
                "customData" : {
                        "employeeId" : 1
                },
                "roles" : [
                        {
                                "role" : "readWrite",
                                "db" : "technicalkeeda"
                        },
                        {
                                "role" : "dbAdmin",
                                "db" : "technicalkeeda"
                        }
                ]
        },
        {
                "_id" : "technicalkeeda.scott",
                "user" : "scott",
                "db" : "technicalkeeda",
                "customData" : {
                        "employeeId" : 9999,
                        "employeeName" : "Yashwant",
                        "dept" : "IT"
                },
                "roles" : [
                        {
                                "role" : "readWrite",
                                "db" : "technicalkeeda"
                        }
                ]
        }
]

> db.changeUserPassword("scott", "newtiger");
>
Yashwant Chavan

Yashwant Chavan

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan@gmail.com