Navigation

Update a Database User

Info With Circle IconCreated with Sketch.Note

Groups and projects are synonymous terms. Your {GROUP-ID} is the same as your project ID. For existing groups, your group/project ID remains the same. The resource and corresponding endpoints use the term groups.

https://cloud.mongodb.com/api/atlas/v1.0

The Atlas API uses HTTP Digest Authentication. Provide your Atlas username as the username and Atlas API key as the password as part of the HTTP request.

This endpoint requires that the Atlas user has the Owner role. To view the available Atlas users, click on Users & Teams in the left-hand navigation.

For complete documentation on configuring API access for an Atlas project, see Configure Atlas API Access.

Send only those fields where you will change the value.

PATCH /api/atlas/v1.0/groups/{GROUP-ID}/databaseUsers/{databaseName}/{USERNAME}

You can update a user's roles and password. Additionally, for temporary users, you can update the user's expiration date or set the user to be permanent. You cannot update the user's name or authentication database, which is admin. You also cannot update permanent users to be temporary.

ParameterRequired/OptionalDescription
GROUP-IDRequired.The unique identifier for the project.
databaseNameRequired.

The user's authentication database.

Accepted values include:

  • $external if the user is authenticated using X.509 certificates, LDAP or AWS IAM.
  • admin users authenticated using SCRAM-SHA.

    This is the default authentication scheme in Atlas.

USERNAMERequired.

The username to update.

Must be a fully qualified distinguished name, as defined in RFC-2253, if:

  • ldapAuthType is USER or GROUP, or
  • x509Type is CUSTOMER.

Must be an URL-encoded AWS ARN if:

  • awsIAMType is USER or ROLE.

The following query parameters are optional:

Query ParameterTypeDescriptionDefault
prettybooleanDisplays response in a prettyprint format.false
envelopebooleanSpecifies whether or not to wrap the response in an envelope.false
NameDescription
deleteAfterDate

Optional ISO-8601-formatted UTC date after which Atlas deletes the user. The specified date must be in the future and within one week of the time you make the API request. To update a temporary user to be permanent, set the value of this field to null.

Info With Circle IconCreated with Sketch.Note

You may include an ISO-8601 time zone designator to ensure that the expiration date occurs with respect to the local time in the specified time zone.

Important With Circle IconCreated with Sketch.Important

You can only modify the expiration date for a user if an expiration date was specified when creating the user. You cannot assign a deleteAfterDate to a permanent user.

labels

Array of documents containing key-value pairs that tag and categorize the database user.

Each key and value has a maximum length of 255 characters.

"labels": [
{
"key": "example key",
"value": "example value"
}
]
roles

Array of this user's roles and the databases / collections on which the roles apply. A role allows the user to perform particular actions on the specified database. A role on the admin database can include privileges that apply to the other databases as well.

Info With Circle IconCreated with Sketch.Note

The available privilege actions for custom roles support a subset of MongoDB commands. See Unsupported Commands in M10+ Clusters for more information.

Important With Circle IconCreated with Sketch.Important

If a user is assigned a custom role, they cannot be assigned any other roles.

roles.databaseNameDatabase on which the user has the specified role. A role on the admin database can include privileges that apply to the other databases.
roles.collectionName

Collection for which the role applies.

You can specify a collection for the read and readWrite roles. If you do not specify a collection for read and readWrite, the role applies to all collections in the database (excluding some collections in the system. database).

Info With Circle IconCreated with Sketch.Note

When applied to a collection, the read and readWrite roles in Atlas differ slightly from the built-in MongoDB read and readWrite roles.

In Atlas, read provides the following collection-level actions:

In Atlas, readWrite provides the same actions as read, as well as the following additional collection-level actions:

roles.roleName

Name of the role. This value can either be a built-in role or a custom role.

The following accepted values of role are restricted to the admin database:

The following accepted values of role can be applied to a specific database:

The following accepted values of role can be applied to a specific collection:

  • read
  • readWrite

If you do not specify a collection for the read and readWrite roles, the roles apply to all collections (excluding some system. collections) in the database.

Info With Circle IconCreated with Sketch.Note

If you specify a custom role name in this field, the roles.databaseName field must be admin.

scopes

Array of clusters and Atlas Data Lakes that the user has access to. If array is empty, Atlas grants the user access to all the clusters and Atlas Data Lakes in the project by default.

"scopes": [
{
"name": <resource-name>,
"type": "CLUSTER"|"DATA_LAKE"
}
]
scopes.nameName of the cluster or Atlas Data Lake that this user can access.
scopes.type

Type of resource that this user has access to. Valid values are:

  • CLUSTER
  • DATA_LAKE
passwordThe user's password. This field is NOT included in the entity returned from the server.

If you set the query element envelope to true, the response is wrapped by the content object.

Response ElementTypeDescription
databaseNamestring

The user's authentication database. A user must provide both a username and authentication database to log into MongoDB.

Returned values include:

  • $external if the user is authenticated using X.509 certificates, LDAP , or AWS IAM.
  • admin users authenticated using SCRAM-SHA.

    This is the default authentication scheme in Atlas.

deleteAfterDatestringTimestamp in ISO 8601 date and time format in UTC after which Atlas deletes the user. This field is only present if an expiration date was specified when creating the entry.
groupIdstringUnique identifier of the Atlas project to which the user belongs.
labelsarray of documentsArray containing key-value pairs that tag and categorize the database user.
ldapAuthTypestring

Method by which the specified username is authenticated. If no value is given, Atlas uses the default value of NONE.

Returned values include:

NONEAtlas authenticates this user through SCRAM-SHA, not LDAP .
USERLDAP server authenticates this user through the user's LDAP user.
GROUPLDAP server authenticates this user using their LDAP user and authorizes this user using their LDAP group. To learn more about LDAP security, see Set up User Authentication and Authorization with LDAP.
x509Typestring

X.509 method by which the provided username is authenticated. If no value is given, Atlas uses the default value of NONE.

The possible types are:

NONEThe user does not use X.509 authentication.
MANAGED

The user is being created for use with Atlas-managed X.509.

Externally authenticated users can only be created on the $external database.

CUSTOMER

The user is being created for use with Self-Managed X.509. Users created with this x509Type require a Common Name (CN) in the username field. To learn more, see RFC 2253.

Externally authenticated users can only be created on the $external database.

awsIAMTypestring

If this value is set, the new database user authenticates with AWS IAM credentials.

Possible response values are:

NONEThe user does not use AWS IAM credentials.
USERNew database user has AWS IAM user credentials.
ROLENew database user has credentials associated with an AWS IAM role.
linksdocument arrayOne or more links to sub-resources and/or related resources.
rolesstring arrayArray of this user's roles and the databases / collections on which the roles apply. A role allows the user to perform particular actions on the specified database. A role on the admin database can include privileges that apply to the other databases as well.
roles
.collectionName
stringCollection on which the user has the specified role.
roles
.databaseName
stringDatabase on which the user has the specified role. A role on the admin database can include privileges that apply to the other databases.
roles
.roleName
string

Name of the role. The accepted values are:

scopesarray of documentsArray of clusters and Atlas Data Lakes that this user has access to. Returns an empty array if the user has access to all the clusters and Atlas Data Lakes in the project. Database users are granted access to all resources by default.
scopes.namestringName of the cluster or Atlas Data Lake that this user has access to.
scopes.typestring

Type of resource that this user has access to. Valid values are:

  • CLUSTER
  • DATA_LAKE
usernamestring

Username for authenticating to MongoDB.

A fully qualified distinguished name, as defined in RFC-2253, is returned if:

  • ldapAuthType is USER or GROUP, or
  • x509Type is CUSTOMER.

An ARN is returned if:

  • awsIAMType is USER or ROLE.

Update one database user that Atlas authenticates using SCRAM-SHA and the admin database.

Important With Circle IconCreated with Sketch.Important

You must modify the following code block with the appropriate credentials and project ID.

curl -i -u "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest -X PATCH \
"https://cloud.mongodb.com/api/atlas/v1.0/groups/5356823b3794dee37132bb7b/databaseUsers/admin/david" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"roles" : [ {
"databaseName" : "service",
"roleName" : "read"
} ]
}'
HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=ISO-8859-1
Date: {dateInUnixFormat}
WWW-Authenticate: Digest realm="MMS Public API", domain="", nonce="{nonce}", algorithm=MD5, op="auth", stale=false
Content-Length: {requestLengthInBytes}
Connection: keep-alive
HTTP/1.1 200 OK
Vary: Accept-Encoding
Content-Type: application/json
Strict-Transport-Security: max-age=300
Date: {dateInUnixFormat}
Connection: keep-alive
Content-Length: {requestLengthInBytes}
{
"databaseName" : "admin",
"groupId" : "5356823b3794dee37132bb7b",
"labels" [],
"links" : [ ... ],
"roles" : [ {
"databaseName" : "service",
"roleName" : "read"
} ],
"scopes": [{
"name": "myCluster",
"type": "CLUSTER"
}],
"username" : "david",
"awsIAMType" : "NONE",
"x509Type" : "NONE",
"ldapAuthType" : "NONE"
}
Give Feedback