Say, I have some POCO
like following.
public class Graph
{
public string Id { get; set; } // Indexed by this
public List<Node> NodeList { get; set; }
}
public class Node
{
public string Id { get; set; }
public string Name { get; set; }
public List<Edge> EdgeList { get; set; }
}
public class Edge
{
public string Id { get; set; }
public double Cost { get; set; }
}
When partially updating my Graph
I want to find an existing Node
in NodeList
by it's Id
, and update it's Name
and Edge
property. I do not want to add new Node
objects in my NodeList
. Only want to update existing ones.
Sofar I've tried:
public void UpdateGraph(string index, Graph graph)
{
var docPath = new DocumentPath<Graph>(graph.Id).Index(index);
try
{
var updateResp = client.Update<Graph, Graph>(docPath, searchDescriptor => searchDescriptor
.Doc(graph)
.RetryOnConflict(4)
.Refresh(true)
);
}
}
In my current implementation as you can see all I am doing is replacing
the old Graph
object. But I want to partially update my Graph
object. I want to send list of Node
object as parameter,
Find those in NodeList
and only update those Node
Objects.
Maybe some thing like the following,
public void UpdateGraph(string index, List<Node> node)
{
//Code here
}
Because
NodeList
is aList<Node>
, a partial update is not possible as the provided value would replace the existing value.You can however use optimistic concurrency control to
Something like the following will work
If the
Graph
has been changed in between the get and the index call, then a 409 response will be returned on the index call.If you regularly need to update
Node
s andEdge
s independently of one another, you may decide to model them with Parent/Child relationships which would allow you to update without needing to pull back the object graph and index the changes.