Navigation

Create a Database User

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.

Base URL: 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 in the left-hand navigation.

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

Atlas supports a maximum of 100 MongoDB users per Atlas project.

Note

If you require more than 100 MongoDB users on a project, please contact Atlas support.

Syntax

POST /api/atlas/v1.0/groups/{GROUP-ID}/databaseUsers

Request Path Parameters

Parameter Required/Optional Description
GROUP-ID Required. The unique identifier for the project.

Request Query Parameters

This endpoint may use any of the HTTP request query parameters available to all Atlas API resources. These are all optional.

Name Type Description Default
pretty boolean Display response in a prettyprint format. false
envelope boolean Specifies whether or not to wrap the response in an envelope. false

Request Body Parameters

Name Description
databaseName The user’s authentication database. A user must provide both a username and authentication database to log into MongoDB. In Atlas deployments of MongoDB, the authentication database is always the admin database.
deleteAfterDate

Optional The 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.

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.

groupId ID of the Atlas project the user belongs to.
username The username for authenticating to MongoDB.
roles An array of the user’s roles and the database on which the user has each role. 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.databaseName The database 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

The 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 the read and readWrite roles, the roles apply to all collections (excluding some system. collections) in the specified database.

roles.roleName

The name of the role.

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

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

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

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.

password The user’s password. This field is NOT included in the entity returned from the server.

Response Elements

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

Name Description
links One or more links to sub-resources and/or related resources.
databaseName The user’s authentication database. A user must provide both a username and authentication database to log into MongoDB. In Atlas deployments of MongoDB, the authentication database is always the admin database.
deleteAfterDate When this user will be deleted. This element is only present if it was specified in the request body.
groupId ID of the Atlas project the user belongs to.
username The username for authenticating to MongoDB.
roles An array of the user’s roles and the database on which the user has each role. 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.databaseName The database 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

The name of the role. The possible values are:

roles.collectionName The collection for which the role applies.

Example Request

Request

Important

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

curl -i -u "username:apiKey" --digest -H "Content-Type: application/json" -X POST "https://cloud.mongodb.com/api/atlas/v1.0/groups/5356823b3794dee37132bb7b/databaseUsers" --data '
{
  "databaseName" : "admin",
  "roles" : [ {
    "databaseName" : "sales",
    "roleName" : "readWrite"
  }, {
    "databaseName" : "marketing",
    "roleName" : "read"
  } ],
  "username" : "david",
  "password" : "changeme123"
}'

Response

HTTP/1.1 201 Created

{
  "databaseName" : "admin",
  "groupId" : "5356823b3794dee37132bb7b",
  "links" : [ ... ],
  "roles" : [ {
    "databaseName" : "sales",
    "roleName" : "readWrite"
  }, {
    "databaseName" : "marketing",
    "roleName" : "read"
  } ],
  "username" : "david"
}