IDocumentWriter<TDocument>.InsertOrUpdateDocumentAsync 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.
Tries to insert or update a document with provided document id with value provided in Document.
public:
System::Threading::Tasks::Task<System::Cloud::DocumentDb::IDatabaseResponse<TDocument> ^> ^ InsertOrUpdateDocumentAsync(System::Cloud::DocumentDb::RequestOptions<TDocument> ^ options, System::String ^ id, Func<TDocument, TDocument> ^ conflictResolveFunc, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.Cloud.DocumentDb.IDatabaseResponse<TDocument>> InsertOrUpdateDocumentAsync(System.Cloud.DocumentDb.RequestOptions<TDocument> options, string id, Func<TDocument,TDocument> conflictResolveFunc, System.Threading.CancellationToken cancellationToken);
abstract member InsertOrUpdateDocumentAsync : System.Cloud.DocumentDb.RequestOptions<'Document> * string * Func<'Document, 'Document> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Cloud.DocumentDb.IDatabaseResponse<'Document>>
Public Function InsertOrUpdateDocumentAsync (options As RequestOptions(Of TDocument), id As String, conflictResolveFunc As Func(Of TDocument, TDocument), cancellationToken As CancellationToken) As Task(Of IDatabaseResponse(Of TDocument))
Parameters
- options
- RequestOptions<TDocument>
The request options.
- id
- String
The document id.
- conflictResolveFunc
- Func<TDocument,TDocument>
Func used to resolve conflict if there are documents in DB.
- cancellationToken
- CancellationToken
The token represents request cancellation.
Returns
A Task containing a IDatabaseResponse<T> that wraps the updated document.
Exceptions
Thrown when an error occurred on a client side. For example on a bad request, permissions error or client timeout.
Thrown when an error occurred on a database server side, including internal server error.
Thrown when a request failed but can be retried. This includes throttling and server not available cases.
A generic exception thrown in all other not covered above cases.
Remarks
This function should only be called if existence status of the target item is unknown. This is different from UpsertDocumentAsync(RequestOptions<TDocument>, CancellationToken) by providing a method for resolving conflicts. If the id in the document different from the id provided, the id will be updated too. After the operation succeed there will be no document with the old id.