DocumentClient.CreateUserAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
CreateUserAsync(String, User, RequestOptions) |
Creates a user object as an asychronous operation in the Azure Cosmos DB service. |
CreateUserAsync(Uri, User, RequestOptions) |
Creates a user as an asychronous operation in the Azure Cosmos DB service. |
CreateUserAsync(String, User, RequestOptions)
Creates a user object as an asychronous operation in the Azure Cosmos DB service.
public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.User>> CreateUserAsync (string databaseLink, Microsoft.Azure.Documents.User user, Microsoft.Azure.Documents.Client.RequestOptions options = default);
abstract member CreateUserAsync : string * Microsoft.Azure.Documents.User * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.User>>
override this.CreateUserAsync : string * Microsoft.Azure.Documents.User * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.User>>
Public Function CreateUserAsync (databaseLink As String, user As User, Optional options As RequestOptions = Nothing) As Task(Of ResourceResponse(Of User))
Parameters
- databaseLink
- String
The link of the database to create the user in. E.g. dbs/db_rid/
- options
- RequestOptions
(Optional) The request options for the request.
Returns
A task object representing the service response for the asynchronous operation which contains the created User object.
Implements
Exceptions
If either databaseLink
or user
is not set.
Represents a consolidation of failures that occured during async processing. Look within InnerExceptions to find the actual exception(s)
This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a Document are:
StatusCode | Reason for exception |
---|---|
400 | BadRequest - This means something was wrong with the request supplied. |
403 | Forbidden - You have reached your quota of user objects for this database. Contact support to have this quota increased. |
409 | Conflict - This means a User with an id matching the id you supplied already existed. |
Examples
//Create a new user called joeBloggs in the specified database
User user = await client.CreateUserAsync(databaseLink, new User { Id = "joeBloggs" });
See also
Applies to
CreateUserAsync(Uri, User, RequestOptions)
Creates a user as an asychronous operation in the Azure Cosmos DB service.
public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.User>> CreateUserAsync (Uri databaseUri, Microsoft.Azure.Documents.User user, Microsoft.Azure.Documents.Client.RequestOptions options = default);
abstract member CreateUserAsync : Uri * Microsoft.Azure.Documents.User * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.User>>
override this.CreateUserAsync : Uri * Microsoft.Azure.Documents.User * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.User>>
Public Function CreateUserAsync (databaseUri As Uri, user As User, Optional options As RequestOptions = Nothing) As Task(Of ResourceResponse(Of User))
Parameters
- databaseUri
- Uri
the URI of the database to create the user in.
- user
- User
the Microsoft.Azure.Documents.User object.
- options
- RequestOptions
The request options for the request.
Returns
The task object representing the service response for the asynchronous operation.
Implements
Applies to
Azure SDK for .NET