12
votes

How do I update an existing property of a node in a graph using Gremlin?

The following method creates two properties "timestamp" with 2 different values, instead of updating the existing property "timestamp":

ContentGraph.g.addV('Filter').property('timestamp', new Date());
ContentGraph.g.V().hasLabel('Filter').property('timestamp', new Date());
1

1 Answers

22
votes

I am not sure which graph DB you are using but some, such as Amazon Neptune, have a default cardinality of set. You can override that cardinality setting using the Cardinality.single enum.

ContentGraph.g.addV('Filter').property('timestamp', new Date());
ContentGraph.g.V().hasLabel('Filter').property(single,'timestamp', new Date());

Hope that helps, Kelvin