Updated on 2022-09-21 GMT+08:00

Updating a User

db.updateUser(username, update, writeConcern)

  • username indicates the username to be updated.
  • update is a document containing the replacement data for the user.
  • writeConcern: The write concern level of the update operation. This parameter is optional.
db.updateUser(
   "<username>",
   {
     customData : { <any information> },
     roles : [
       { role: "<role>", db: "<database>" } | "<role>",
       ...
     ],
     pwd: passwordPrompt(),      // Or  "<cleartext password>"
     authenticationRestrictions: [
        {
          clientSource: ["<IP>" | "<CIDR range>", ...],
          serverAddress: ["<IP>", | "<CIDR range>", ...]
        },
        ...
     ],
     mechanisms: [ "<SCRAM-SHA-1|SCRAM-SHA-256>", ... ],
     passwordDigestor: "<server|client>"
   },
   writeConcern: { <write concern> }
)
Table 1 update description

Field

Type

Description

customData

Documents

Optional. Any information.

roles

Array

Optional. The role assigned to the user. An update to the roles array overrides the previous array's values.

pwd

string

Optional. The user's password.

authenticationRestrictions

Array

Optional. The IP address or CIDR blocks that can be accessed by a role.

mechanisms

Array

Optional. The specific SCRAM mechanism or mechanisms for the user credentials. Valid values are SCRAM-SHA-1 and SCRAM-SHA-256.

passwordDigestor

string

Optional. Whether to verify the password on the server or client. The default value is server.