MongoDB: db.changeUserPassword() method
db.changeUserPassword()
The db.changeUserPassword() method is used to changes an existing user’s password.
Syntax:
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.
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
username | Specifies an existing username with access privileges for this database. | Required | string |
password | Specifies the corresponding password. | Required | string |
mechanism | Specifies the authentication mechanism used. Defaults to either:
|
Optional | string |
digestPassword | 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. | Optional | boolean |
Example: MongoDB: db.changeUserPassword() method
Given a user mynewuser in the test database with the following user info:
> db.getUser("mynewuser");
{
"_id" : "test.mynewuser",
"user" : "mynewuser",
"db" : "test",
"roles" : [
{
"role" : "read",
"db" : "assets"
}
],
"customData" : {
"employeeId" : "0x3039"
}
}
The following operation changes the password of the user named mynewuser in the test database to user1234.
db.changeUserPassword("mynewuser", "user1234");
Retrieve the restaurants data from here
Required Access
To modify the password of another user on a database, you must have the changeAnyPassword action on that database.
Previous:
db.updateUser() method
Next:
db.dropAllUsers() method
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mongodb/shell-methods/user-management/db-changeUserPassword.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics