DB - Updateuser - MongoDB Manual
DB - Updateuser - MongoDB Manual
DB - Updateuser - MongoDB Manual
On this page
db.updateUser() Definition
Behavior
Definition
Required Access
db.updateUser( username, update, writeConcern )
Example
Updates the user's profile on the database on which you run the
method.
An update to a field completely replaces the previous field's
values.
This includes updates to the user's roles array.
WAR N I NG
TI P
Give Feedback
Parameter Type Description
customDat
document Optional. Any arbitrary information.
a
Give Feedback
Field Type Description
Give Feedback
Field Type Description
Example
Give Feedback
Field Type Description
"SCRAM-SHA-1"
Uses the SHA-1 hashing function.
"SCRAM-SHA-256"
Uses the SHA-256 hashing function.
Requires featureCompatibilityVersion
set to 4.0.
Requires passwordDigestor to be
server.
Give Feedback
Field Type Description
Behavior
The server receives undigested
password from the client and Required Access
digests the password.
Example
Roles
"readWrite"
Or you can specify the role with a document, as in: Give Feedback
{ role: "<role>", db: "<database>" }
On this page
Authentication Restrictions
Definition
New in version 3.6.
Behavior
Field
Value Description
Name
I M PORTANT
On this page
Required Access
Behavior
Example
Replica set
Encyption
WAR N I NG
Required Access
Give Feedback
You must have access that includes the revokeRole
action on all
databases in order to update a
user's roles array.
You must have the grantRole action on a role's database to add a role to
a user.
On this page
To change another user's pwd or customData field, you must have
the
changePassword and changeCustomData
actions respectively on that Definition
user's database. Behavior
To modify your own password and custom data, you must have privileges Required Access
that grant changeOwnPassword and
changeOwnCustomData actions Example
respectively on the user's database.
Example
Given a user appClient01 in the products database with the following
user info:
{
_id : "products.appClient01",
userId : UUID("c5d88855-3f1e-46cb-9c8b-269bef957986"),
user : "appClient01",
db : "products",
customData : { empID : "12345", badge : "9156" },
roles : [
{
role : "readWrite",
db : "products"
},
{
role : "read",
db : "inventory"
}
],
mechanisms : [ // Starting in MongoDB 4.0
"SCRAM-SHA-1", Give Feedback
"SCRAM-SHA-256"
],
authenticationRestrictions : [ {
clientSource: ["69.89.31.226"],
serverAddress: ["172.16.254.1"]
} ] On this page
}
Definition
Behavior
The following db.updateUser() method completely replaces the
user's
Required Access
customData and roles data:
Example
use products
db.updateUser( "appClient01",
{
customData : { employeeId : "0x3039" },
roles : [
{ role : "read", db : "assets" }
]
} )
The user appClient01 in the products database now has the following
user information:
{
_id : "products.appClient01",
userId : UUID("c5d88855-3f1e-46cb-9c8b-269bef957986"),
user : "appClient01",
db : "products",
customData : { employeeId : "0x3039" },
roles : [
{
role : "read",
db : "assets"
}
], Give Feedback
mechanisms : [ // Starting in MongoDB 4.0
"SCRAM-SHA-1",
"SCRAM-SHA-256"
],
authenticationRestrictions : [ {
clientSource: ["69.89.31.226"], On this page
serverAddress: ["172.16.254.1"]
} ] Definition
}
Behavior
Required Access
NOTE
NOTE
Required Access
Example
Give Feedback