Operations: Server: How to Modify a Conflict Solver

The conflict solver allows you to set a conflict resolution script for each collection or resolve conflicts using the latest version.

To modify the solver configuration, use ModifyConflictSolverOperation.

Syntax

public ModifyConflictSolverOperation(
    string database, 
    Dictionary<string, ScriptResolver> collectionByScript = null, 
    bool resolveToLatest = false)

public class ScriptResolver
{
    public string Script { get; set; }
}
Parameters
database string Name of a database
collectionByScript Dictionary<string,ScriptResolver> Per collection conflict resolution script
resolveToLatest bool Indicates if a conflict should be resolved using the latest version
Return Value
Key Name of database
RaftCommandIndex RAFT command index
Solver Saved conflict solver configuration

Example I

// resolve conflict to latest version
ModifyConflictSolverOperation operation = 
    new ModifyConflictSolverOperation("Northwind", null, resolveToLatest: true);
store.Maintenance.Server.Send(operation);

Example II

// resolve conflict by finding max value 
string script = @"
var maxRecord = 0;
for (var i = 0; i < docs.length; i++) {
    maxRecord = Math.max(docs[i].maxRecord, maxRecord);   
}
docs[0].MaxRecord = maxRecord;

return docs[0];";

ModifyConflictSolverOperation operation = 
    new ModifyConflictSolverOperation("Northwind", new Dictionary<string, ScriptResolver>
    {
        { "Orders", new ScriptResolver { Script = script} }
    }, resolveToLatest: false);
store.Maintenance.Server.Send(operation);