Class ConflictResolutionPolicy
Represents the conflict resolution policy configuration for specifying how to resolve conflicts in case writes from different regions result in conflicts on documents in the collection in the Azure Cosmos DB service.
public sealed class ConflictResolutionPolicy : JsonSerializable
- Inheritance
-
ConflictResolutionPolicy
- Inherited Members
- Extension Methods
Examples
A collection with custom conflict resolution with no user-registered stored procedure.
var collectionSpec = new DocumentCollection { Id = "Multi-master collection", ConflictResolutionPolicy policy = new ConflictResolutionPolicy { Mode = ConflictResolutionMode.Custom } }; DocumentCollection collection = await client.CreateDocumentCollectionAsync(databaseLink, collectionSpec });
A collection with custom conflict resolution with a user-registered stored procedure.
var collectionSpec = new DocumentCollection { Id = "Multi-master collection", ConflictResolutionPolicy policy = new ConflictResolutionPolicy { Mode = ConflictResolutionMode.Custom, ConflictResolutionProcedure = "conflictResolutionSprocName" } }; DocumentCollection collection = await client.CreateDocumentCollectionAsync(databaseLink, collectionSpec });
A collection with last writer wins conflict resolution, based on a path in the conflicting documents.
var collectionSpec = new DocumentCollection { Id = "Multi-master collection", ConflictResolutionPolicy policy = new ConflictResolutionPolicy { Mode = ConflictResolutionMode.LastWriterWins, ConflictResolutionPath = "/path/for/conflict/resolution" } }; DocumentCollection collection = await client.CreateDocumentCollectionAsync(databaseLink, collectionSpec });
Constructors
ConflictResolutionPolicy()
Initializes a new instance of the ConflictResolutionPolicy class for the Azure Cosmos DB service.
public ConflictResolutionPolicy()
Properties
ConflictResolutionPath
Gets or sets the path which is present in each document in the Azure Cosmos DB service for last writer wins conflict-resolution. This path must be present in each document and must be an integer value. In case of a conflict occuring on a document, the document with the higher integer value in the specified path will be picked. If the path is unspecified, by default the Timestamp path will be used.
public string ConflictResolutionPath { get; set; }
Property Value
- string
The path to check values for last-writer wins conflict resolution. That path is a rooted path of the property in the document, such as "/name/first".
Examples
conflictResolutionPolicy.ConflictResolutionPath = "/name/first";
Remarks
This value should only be set when using LastWriterWins
ConflictResolutionProcedure
Gets or sets the StoredProcedure which is used for conflict resolution in the Azure Cosmos DB service. This stored procedure may be created after the DocumentCollection is created and can be changed as required.
public string ConflictResolutionProcedure { get; set; }
Property Value
- string
The stored procedure to perform conflict resolution.
Examples
conflictResolutionPolicy.ConflictResolutionProcedure = "/name/first";
Remarks
- This value should only be set when using Custom
- In case the stored procedure fails or throws an exception, the conflict resolution will default to registering conflicts in the conflicts feed"/>.
- The user can provide the stored procedure Id or ResourceId.
Mode
Gets or sets the ConflictResolutionMode in the Azure Cosmos DB service. By default it is LastWriterWins.
public ConflictResolutionMode Mode { get; set; }
Property Value
- ConflictResolutionMode
One of the values of the ConflictResolutionMode enumeration.