# How to change the password in MongoDB for existing user?

To change the password in MongoDB for existing user, you can use changeUserPassword(). Following is the syntax

db.changeUserPassword("yourExistingUserName", "yourPassword");

Let us first switch the database to admin. Following is the syntax

> use admin

This will produce the following output

switched to db admin

Now, display users from the database. Following is the query

> db.getUsers();

This will produce the following output

[
{
"user" : "John",
"roles" : [
{
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
]

Following is the query to change the password for user “John”

> db.changeUserPassword("John", "123456");

Now the password has been changed with value “123456”.