Navigation
This version has reached end of life on October 2016. Learn more about upgrading your version of MongoDB.

db.changeUserPassword()

Definition

db.changeUserPassword(username, password)

Updates a user’s password. Run the method in the database where the user is defined, i.e. the database you created the user.

Parameter Type Description
username string Specifies an existing username with access privileges for this database.
password string Specifies the corresponding password.
mechanism string

Optional. Specifies the authentication mechanism used. Defaults to MONGODB-CR.

For available mechanisms, see authentication mechanisms.

digestPassword boolean Optional. Determines whether the server receives digested or undigested password. Set to false to specify undigested password. For use with SASL/LDAP authentication since the server must forward an undigested password to saslauthd.

Required Access

You must have the changeAnyPassword action on a database to modify the password of any user on that database.

To change your own password, you must have the changeOwnPassword action on your database. See Change Your Password and Custom Data.

Example

The following operation changes the password of the user named accountUser in the products database to SOh3TbYhx8ypJPxmt1oOfL:

use products
db.changeUserPassword("accountUser", "SOh3TbYhx8ypJPxmt1oOfL")