# Users

How to manage users of a database cluster.

## Get all Cluster Users

> Retrieves a list of MongoDB users.

```json
{"openapi":"3.0.3","info":{"title":"IONOS DBaaS MongoDB REST API","version":"1.0.0"},"tags":[{"name":"Users","description":"How to manage users of a database cluster."}],"servers":[{"url":"https://api.ionos.com/databases/mongodb","description":"Production"}],"security":[{"basicAuth":[]},{"tokenAuth":[]}],"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic","description":"For 'Basic' authentication, take your credentials by first combining the username and password with a colon (``username:password``) and then encoding the resulting string in base64 (``YWxhZGRpbjpvcGVuc2VzYW1l``).\n\n**Example Request Header**\n\n``Authorization: Basic YWxhZGRpbjpvcGVuc2Vzl``\n\nMore details: https://en.wikipedia.org/wiki/Basic_access_authentication\n"},"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Authorization is granted when a valid proof of identity is provided along with an API request for data. This proof of identity is in the form of a JSON web access token, a unique string that identifies a user.\n\n**Example Request Header**\n\n``Authorization: Bearer ACCESS_TOKEN``\n"}},"parameters":{"PaginationLimit":{"name":"limit","in":"query","description":"The maximum number of elements to return. Use together with 'offset' for pagination.","required":false,"schema":{"type":"integer","default":100,"maximum":1000,"minimum":1}},"PaginationOffset":{"name":"offset","in":"query","description":"The first element to return. Use together with 'limit' for pagination.","required":false,"schema":{"type":"integer","default":0}},"ClusterIdPath":{"name":"clusterId","in":"path","description":"The unique ID of the cluster.","required":true,"schema":{"type":"string"}}},"schemas":{"UsersList":{"description":"List of cluster users.","properties":{"type":{"$ref":"#/components/schemas/ResourceType"},"id":{"$ref":"#/components/schemas/ResourceId"},"items":{"type":"array","items":{"$ref":"#/components/schemas/User"}}},"type":"object"},"ResourceType":{"description":"The resource type.","type":"string","enum":["collection","cluster","user","snapshot","template"]},"ResourceId":{"type":"string","description":"The unique ID of the resource."},"User":{"description":"MongoDB database user.","properties":{"type":{"allOf":[{"$ref":"#/components/schemas/ResourceType"}]},"metadata":{"$ref":"#/components/schemas/UserMetadata"},"properties":{"$ref":"#/components/schemas/UserProperties"}},"type":"object"},"UserMetadata":{"description":"The metadata of the resource.","properties":{"createdDate":{"type":"string","format":"date-time","description":"The date the resource was created."},"createdBy":{"type":"string","description":"The user who created the resource."},"createdByUserId":{"type":"string","description":"The ID of the user who created the resource."}}},"UserProperties":{"description":"Mongodb user properties.","required":["username"],"properties":{"username":{"type":"string"},"roles":{"type":"array","items":{"$ref":"#/components/schemas/UserRoles"}}}},"UserRoles":{"description":"a list of mongodb user role.","properties":{"role":{"type":"string","enum":["read","readWrite","dbAdmin","clusterMonitor","readAnyDatabase","readWriteAnyDatabase","dbAdminAnyDatabase","enableSharding"]},"database":{"type":"string"}},"type":"object"},"ErrorResponse":{"properties":{"httpStatus":{"type":"integer","description":"The HTTP status code of the operation."},"messages":{"type":"array","items":{"$ref":"#/components/schemas/ErrorMessage"}}},"type":"object"},"ErrorMessage":{"properties":{"errorCode":{"type":"string","description":"Application internal error code.\n"},"message":{"type":"string","description":"A human readable explanation specific to this occurrence of the\nproblem.\n"}},"type":"object"}},"responses":{"ApiError":{"description":"Any erroneous status code: 400 (parse error), 401 (authorization error),\n402 (trial access), 403 (insufficient permissions), 404 (not found),\n405 (unsupported HTTP method), 415 (unsupported content type),\n422 (validation error), 429 (request rate limit exceeded),\n500 (server error), 503 (maintenance)\n","headers":{"Content-Type":{"description":"The content type of the response.","schema":{"type":"string","default":"application/problem+json"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/clusters/{clusterId}/users":{"get":{"operationId":"clustersUsersGet","summary":"Get all Cluster Users","description":"Retrieves a list of MongoDB users.","tags":["Users"],"parameters":[{"$ref":"#/components/parameters/PaginationLimit"},{"$ref":"#/components/parameters/PaginationOffset"},{"$ref":"#/components/parameters/ClusterIdPath"}],"responses":{"200":{"description":"Successful operation.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsersList"}}}},"default":{"$ref":"#/components/responses/ApiError"}}}}}}
```

## Create a MongoDB User

> Creates a MongoDB user.<br>

```json
{"openapi":"3.0.3","info":{"title":"IONOS DBaaS MongoDB REST API","version":"1.0.0"},"tags":[{"name":"Users","description":"How to manage users of a database cluster."}],"servers":[{"url":"https://api.ionos.com/databases/mongodb","description":"Production"}],"security":[{"basicAuth":[]},{"tokenAuth":[]}],"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic","description":"For 'Basic' authentication, take your credentials by first combining the username and password with a colon (``username:password``) and then encoding the resulting string in base64 (``YWxhZGRpbjpvcGVuc2VzYW1l``).\n\n**Example Request Header**\n\n``Authorization: Basic YWxhZGRpbjpvcGVuc2Vzl``\n\nMore details: https://en.wikipedia.org/wiki/Basic_access_authentication\n"},"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Authorization is granted when a valid proof of identity is provided along with an API request for data. This proof of identity is in the form of a JSON web access token, a unique string that identifies a user.\n\n**Example Request Header**\n\n``Authorization: Bearer ACCESS_TOKEN``\n"}},"parameters":{"ClusterIdPath":{"name":"clusterId","in":"path","description":"The unique ID of the cluster.","required":true,"schema":{"type":"string"}}},"schemas":{"PostUserRequest":{"description":"MongoDB database user post request.","properties":{"metadata":{"$ref":"#/components/schemas/UserMetadata"},"properties":{"$ref":"#/components/schemas/PostUserProperties"}}},"UserMetadata":{"description":"The metadata of the resource.","properties":{"createdDate":{"type":"string","format":"date-time","description":"The date the resource was created."},"createdBy":{"type":"string","description":"The user who created the resource."},"createdByUserId":{"type":"string","description":"The ID of the user who created the resource."}}},"PostUserProperties":{"description":"MongoDB database user post request properties.","allOf":[{"$ref":"#/components/schemas/UserProperties"},{"type":"object","required":["password"],"properties":{"password":{"type":"string","writeOnly":true,"minLength":10}}}]},"UserProperties":{"description":"Mongodb user properties.","required":["username"],"properties":{"username":{"type":"string"},"roles":{"type":"array","items":{"$ref":"#/components/schemas/UserRoles"}}}},"UserRoles":{"description":"a list of mongodb user role.","properties":{"role":{"type":"string","enum":["read","readWrite","dbAdmin","clusterMonitor","readAnyDatabase","readWriteAnyDatabase","dbAdminAnyDatabase","enableSharding"]},"database":{"type":"string"}},"type":"object"},"User":{"description":"MongoDB database user.","properties":{"type":{"allOf":[{"$ref":"#/components/schemas/ResourceType"}]},"metadata":{"$ref":"#/components/schemas/UserMetadata"},"properties":{"$ref":"#/components/schemas/UserProperties"}},"type":"object"},"ResourceType":{"description":"The resource type.","type":"string","enum":["collection","cluster","user","snapshot","template"]},"ErrorResponse":{"properties":{"httpStatus":{"type":"integer","description":"The HTTP status code of the operation."},"messages":{"type":"array","items":{"$ref":"#/components/schemas/ErrorMessage"}}},"type":"object"},"ErrorMessage":{"properties":{"errorCode":{"type":"string","description":"Application internal error code.\n"},"message":{"type":"string","description":"A human readable explanation specific to this occurrence of the\nproblem.\n"}},"type":"object"}},"responses":{"ApiError":{"description":"Any erroneous status code: 400 (parse error), 401 (authorization error),\n402 (trial access), 403 (insufficient permissions), 404 (not found),\n405 (unsupported HTTP method), 415 (unsupported content type),\n422 (validation error), 429 (request rate limit exceeded),\n500 (server error), 503 (maintenance)\n","headers":{"Content-Type":{"description":"The content type of the response.","schema":{"type":"string","default":"application/problem+json"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/clusters/{clusterId}/users":{"post":{"operationId":"clustersUsersPost","summary":"Create a MongoDB User","description":"Creates a MongoDB user.\n","tags":["Users"],"parameters":[{"$ref":"#/components/parameters/ClusterIdPath"}],"requestBody":{"description":"The user to be created.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PostUserRequest"}}},"required":true},"responses":{"200":{"description":"The created user is returned with metadata indicating when the user was created and by whom.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User"}}}},"default":{"$ref":"#/components/responses/ApiError"}}}}}}
```

## Get a MongoDB User by ID

> Retrieves the MongoDB user identified by the username.

```json
{"openapi":"3.0.3","info":{"title":"IONOS DBaaS MongoDB REST API","version":"1.0.0"},"tags":[{"name":"Users","description":"How to manage users of a database cluster."}],"servers":[{"url":"https://api.ionos.com/databases/mongodb","description":"Production"}],"security":[{"basicAuth":[]},{"tokenAuth":[]}],"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic","description":"For 'Basic' authentication, take your credentials by first combining the username and password with a colon (``username:password``) and then encoding the resulting string in base64 (``YWxhZGRpbjpvcGVuc2VzYW1l``).\n\n**Example Request Header**\n\n``Authorization: Basic YWxhZGRpbjpvcGVuc2Vzl``\n\nMore details: https://en.wikipedia.org/wiki/Basic_access_authentication\n"},"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Authorization is granted when a valid proof of identity is provided along with an API request for data. This proof of identity is in the form of a JSON web access token, a unique string that identifies a user.\n\n**Example Request Header**\n\n``Authorization: Bearer ACCESS_TOKEN``\n"}},"parameters":{"ClusterIdPath":{"name":"clusterId","in":"path","description":"The unique ID of the cluster.","required":true,"schema":{"type":"string"}},"UsernamePath":{"name":"username","in":"path","description":"The authentication username.","required":true,"schema":{"type":"string"}}},"schemas":{"User":{"description":"MongoDB database user.","properties":{"type":{"allOf":[{"$ref":"#/components/schemas/ResourceType"}]},"metadata":{"$ref":"#/components/schemas/UserMetadata"},"properties":{"$ref":"#/components/schemas/UserProperties"}},"type":"object"},"ResourceType":{"description":"The resource type.","type":"string","enum":["collection","cluster","user","snapshot","template"]},"UserMetadata":{"description":"The metadata of the resource.","properties":{"createdDate":{"type":"string","format":"date-time","description":"The date the resource was created."},"createdBy":{"type":"string","description":"The user who created the resource."},"createdByUserId":{"type":"string","description":"The ID of the user who created the resource."}}},"UserProperties":{"description":"Mongodb user properties.","required":["username"],"properties":{"username":{"type":"string"},"roles":{"type":"array","items":{"$ref":"#/components/schemas/UserRoles"}}}},"UserRoles":{"description":"a list of mongodb user role.","properties":{"role":{"type":"string","enum":["read","readWrite","dbAdmin","clusterMonitor","readAnyDatabase","readWriteAnyDatabase","dbAdminAnyDatabase","enableSharding"]},"database":{"type":"string"}},"type":"object"},"ErrorResponse":{"properties":{"httpStatus":{"type":"integer","description":"The HTTP status code of the operation."},"messages":{"type":"array","items":{"$ref":"#/components/schemas/ErrorMessage"}}},"type":"object"},"ErrorMessage":{"properties":{"errorCode":{"type":"string","description":"Application internal error code.\n"},"message":{"type":"string","description":"A human readable explanation specific to this occurrence of the\nproblem.\n"}},"type":"object"}},"responses":{"ApiError":{"description":"Any erroneous status code: 400 (parse error), 401 (authorization error),\n402 (trial access), 403 (insufficient permissions), 404 (not found),\n405 (unsupported HTTP method), 415 (unsupported content type),\n422 (validation error), 429 (request rate limit exceeded),\n500 (server error), 503 (maintenance)\n","headers":{"Content-Type":{"description":"The content type of the response.","schema":{"type":"string","default":"application/problem+json"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/clusters/{clusterId}/users/{username}":{"get":{"operationId":"clustersUsersFindById","summary":"Get a MongoDB User by ID","description":"Retrieves the MongoDB user identified by the username.","tags":["Users"],"parameters":[{"$ref":"#/components/parameters/ClusterIdPath"},{"$ref":"#/components/parameters/UsernamePath"}],"responses":{"200":{"description":"The user identified by the username and database parameters is returned.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User"}}}},"default":{"$ref":"#/components/responses/ApiError"}}}}}}
```

## Delete a MongoDB User by ID

> Deletes a MongoDB user specified by its ID.

```json
{"openapi":"3.0.3","info":{"title":"IONOS DBaaS MongoDB REST API","version":"1.0.0"},"tags":[{"name":"Users","description":"How to manage users of a database cluster."}],"servers":[{"url":"https://api.ionos.com/databases/mongodb","description":"Production"}],"security":[{"basicAuth":[]},{"tokenAuth":[]}],"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic","description":"For 'Basic' authentication, take your credentials by first combining the username and password with a colon (``username:password``) and then encoding the resulting string in base64 (``YWxhZGRpbjpvcGVuc2VzYW1l``).\n\n**Example Request Header**\n\n``Authorization: Basic YWxhZGRpbjpvcGVuc2Vzl``\n\nMore details: https://en.wikipedia.org/wiki/Basic_access_authentication\n"},"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Authorization is granted when a valid proof of identity is provided along with an API request for data. This proof of identity is in the form of a JSON web access token, a unique string that identifies a user.\n\n**Example Request Header**\n\n``Authorization: Bearer ACCESS_TOKEN``\n"}},"parameters":{"ClusterIdPath":{"name":"clusterId","in":"path","description":"The unique ID of the cluster.","required":true,"schema":{"type":"string"}},"UsernamePath":{"name":"username","in":"path","description":"The authentication username.","required":true,"schema":{"type":"string"}}},"schemas":{"User":{"description":"MongoDB database user.","properties":{"type":{"allOf":[{"$ref":"#/components/schemas/ResourceType"}]},"metadata":{"$ref":"#/components/schemas/UserMetadata"},"properties":{"$ref":"#/components/schemas/UserProperties"}},"type":"object"},"ResourceType":{"description":"The resource type.","type":"string","enum":["collection","cluster","user","snapshot","template"]},"UserMetadata":{"description":"The metadata of the resource.","properties":{"createdDate":{"type":"string","format":"date-time","description":"The date the resource was created."},"createdBy":{"type":"string","description":"The user who created the resource."},"createdByUserId":{"type":"string","description":"The ID of the user who created the resource."}}},"UserProperties":{"description":"Mongodb user properties.","required":["username"],"properties":{"username":{"type":"string"},"roles":{"type":"array","items":{"$ref":"#/components/schemas/UserRoles"}}}},"UserRoles":{"description":"a list of mongodb user role.","properties":{"role":{"type":"string","enum":["read","readWrite","dbAdmin","clusterMonitor","readAnyDatabase","readWriteAnyDatabase","dbAdminAnyDatabase","enableSharding"]},"database":{"type":"string"}},"type":"object"},"ErrorResponse":{"properties":{"httpStatus":{"type":"integer","description":"The HTTP status code of the operation."},"messages":{"type":"array","items":{"$ref":"#/components/schemas/ErrorMessage"}}},"type":"object"},"ErrorMessage":{"properties":{"errorCode":{"type":"string","description":"Application internal error code.\n"},"message":{"type":"string","description":"A human readable explanation specific to this occurrence of the\nproblem.\n"}},"type":"object"}},"responses":{"ApiError":{"description":"Any erroneous status code: 400 (parse error), 401 (authorization error),\n402 (trial access), 403 (insufficient permissions), 404 (not found),\n405 (unsupported HTTP method), 415 (unsupported content type),\n422 (validation error), 429 (request rate limit exceeded),\n500 (server error), 503 (maintenance)\n","headers":{"Content-Type":{"description":"The content type of the response.","schema":{"type":"string","default":"application/problem+json"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/clusters/{clusterId}/users/{username}":{"delete":{"operationId":"clustersUsersDelete","summary":"Delete a MongoDB User by ID","description":"Deletes a MongoDB user specified by its ID.","tags":["Users"],"parameters":[{"$ref":"#/components/parameters/ClusterIdPath"},{"$ref":"#/components/parameters/UsernamePath"}],"responses":{"200":{"description":"The user identified by the username and database parameters will be deleted from the cluster.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User"}}}},"default":{"$ref":"#/components/responses/ApiError"}}}}}}
```

## Patch a MongoDB User by ID

> Patches a MongoDB user specified by its ID.

```json
{"openapi":"3.0.3","info":{"title":"IONOS DBaaS MongoDB REST API","version":"1.0.0"},"tags":[{"name":"Users","description":"How to manage users of a database cluster."}],"servers":[{"url":"https://api.ionos.com/databases/mongodb","description":"Production"}],"security":[{"basicAuth":[]},{"tokenAuth":[]}],"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic","description":"For 'Basic' authentication, take your credentials by first combining the username and password with a colon (``username:password``) and then encoding the resulting string in base64 (``YWxhZGRpbjpvcGVuc2VzYW1l``).\n\n**Example Request Header**\n\n``Authorization: Basic YWxhZGRpbjpvcGVuc2Vzl``\n\nMore details: https://en.wikipedia.org/wiki/Basic_access_authentication\n"},"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Authorization is granted when a valid proof of identity is provided along with an API request for data. This proof of identity is in the form of a JSON web access token, a unique string that identifies a user.\n\n**Example Request Header**\n\n``Authorization: Bearer ACCESS_TOKEN``\n"}},"parameters":{"ClusterIdPath":{"name":"clusterId","in":"path","description":"The unique ID of the cluster.","required":true,"schema":{"type":"string"}},"UsernamePath":{"name":"username","in":"path","description":"The authentication username.","required":true,"schema":{"type":"string"}}},"schemas":{"PatchUserRequest":{"description":"MongoDB database user patch request.","properties":{"metadata":{"$ref":"#/components/schemas/UserMetadata"},"properties":{"$ref":"#/components/schemas/PatchUserProperties"}}},"UserMetadata":{"description":"The metadata of the resource.","properties":{"createdDate":{"type":"string","format":"date-time","description":"The date the resource was created."},"createdBy":{"type":"string","description":"The user who created the resource."},"createdByUserId":{"type":"string","description":"The ID of the user who created the resource."}}},"PatchUserProperties":{"description":"MongoDB database user patch request properties.","properties":{"password":{"type":"string","writeOnly":true,"minLength":10},"roles":{"type":"array","items":{"$ref":"#/components/schemas/UserRoles"}}}},"UserRoles":{"description":"a list of mongodb user role.","properties":{"role":{"type":"string","enum":["read","readWrite","dbAdmin","clusterMonitor","readAnyDatabase","readWriteAnyDatabase","dbAdminAnyDatabase","enableSharding"]},"database":{"type":"string"}},"type":"object"},"User":{"description":"MongoDB database user.","properties":{"type":{"allOf":[{"$ref":"#/components/schemas/ResourceType"}]},"metadata":{"$ref":"#/components/schemas/UserMetadata"},"properties":{"$ref":"#/components/schemas/UserProperties"}},"type":"object"},"ResourceType":{"description":"The resource type.","type":"string","enum":["collection","cluster","user","snapshot","template"]},"UserProperties":{"description":"Mongodb user properties.","required":["username"],"properties":{"username":{"type":"string"},"roles":{"type":"array","items":{"$ref":"#/components/schemas/UserRoles"}}}},"ErrorResponse":{"properties":{"httpStatus":{"type":"integer","description":"The HTTP status code of the operation."},"messages":{"type":"array","items":{"$ref":"#/components/schemas/ErrorMessage"}}},"type":"object"},"ErrorMessage":{"properties":{"errorCode":{"type":"string","description":"Application internal error code.\n"},"message":{"type":"string","description":"A human readable explanation specific to this occurrence of the\nproblem.\n"}},"type":"object"}},"responses":{"ApiError":{"description":"Any erroneous status code: 400 (parse error), 401 (authorization error),\n402 (trial access), 403 (insufficient permissions), 404 (not found),\n405 (unsupported HTTP method), 415 (unsupported content type),\n422 (validation error), 429 (request rate limit exceeded),\n500 (server error), 503 (maintenance)\n","headers":{"Content-Type":{"description":"The content type of the response.","schema":{"type":"string","default":"application/problem+json"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/clusters/{clusterId}/users/{username}":{"patch":{"operationId":"clustersUsersPatch","summary":"Patch a MongoDB User by ID","description":"Patches a MongoDB user specified by its ID.","tags":["Users"],"parameters":[{"$ref":"#/components/parameters/ClusterIdPath"},{"$ref":"#/components/parameters/UsernamePath"}],"requestBody":{"description":"Part of the MongoDB user which should be modified.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatchUserRequest"}}},"required":true},"responses":{"200":{"description":"The user identified by the username and database parameters will be patched.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User"}}}},"default":{"$ref":"#/components/responses/ApiError"}}}}}}
```
