Reputation: 638
I am trying to store a list of changes made to a Vertex in the Vertex itself. Ideally I would want something like this:
{
"id": "95fcfa87-1c03-436d-b3ca-340cea926ee9",
"label": "person",
"type": "vertex",
"log": [{
"user": "[email protected]",
"action": "update",
"timestamp": "22-03-2017",
"field": "firstName",
"oldValue": "Marco"
}
]
}
Using this method chain I am able to a achieve the following structure
graph.addV('person')
.property('firstName', 'Thomas')
.property(list, 'log', '22-03-2017')
.properties('log')
.hasValue('22-03-2017', '21-03-2017')
.property('user','[email protected]')
.property('action', 'update')
.property('field', 'firstName')
.property('oldValue', 'Marco')
{ "id": "95fcfa87-1c03-436d-b3ca-340cea926ee9", "label": "person", "type": "vertex", "properties": { "firstName": [{ "id": "f23482a9-48bc-44e0-b783-3b74a2439a11", "value": "Thomas" } ], "log": [{ "id": "5cfa35e1-e453-42e2-99b1-eb64cd853f22", "value": "22-03-2017", "properties": { "user": "[email protected]", "action": "update", "field": "firstName", "oldValue": "Marco" } } ] } }
However this seems overly complex, as I will have to store a value and add properties to it.
Is it possible to add anonymous objects (i.e. without id
and value
) with the above mentioned data?
Upvotes: 1
Views: 735
Reputation: 3848
Not an actual solution to storing proper objects in a history log, but if you just use it as a log and don't have to access or query it by its properties, you could just put the serialised JSON in the value?
Something like along these lines should approximate the structure you're requesting:
dynamic entry = new JObject();
entry.user = "[email protected]";
entry.action = "update";
entry.timestamp = "22-03-2017 12:34:56";
entry.field = "firstName";
entry.oldValue = "Marco";
graph.addV('person')
.property('firstName', 'Thomas')
.property(list, 'log', entry.ToString());
{ "id": "95fcfa87-1c03-436d-b3ca-340cea926ee9", "label": "person", "type": "vertex", "properties": { "firstName": [{ "id": "f23482a9-48bc-44e0-b783-3b74a2439a11", "value": "Thomas" } ], "log": [{ "id": "5cfa35e1-e453-42e2-99b1-eb64cd853f22", "value": "{\"user\":\"[email protected]\",\"action\":\"update\",\"timestamp\":\"22-03-2017\",\"field\":\"firstName\",\"oldValue\":\"Marco\"}" } ] } }
These log entries can easily be read, deserialised, used, and presented, but will not do much for queriability.
Upvotes: 1