Skip to main content

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
databasestringName of a database
collectionByScriptDictionary<string,ScriptResolver>Per collection conflict resolution script
resolveToLatestboolIndicates if a conflict should be resolved using the latest version
Return Value
KeyName of database
RaftCommandIndexRAFT command index
SolverSaved 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);