MongoDB Change User Password

By Yashwant Chavan, Views 1429, Last updated on 01-Mar-2019

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

Yashwant

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[at][gmail.com]