Search code examples
gremlinamazon-neptune

How to delete/update an attribute value in AWS Neptune with Gremlin?


I'm building a GraphDB with AWS Neptune. In my application, some attributes of a Vertex will be have multi-values. I'm having trouble to figure out a decent approach to remove/update a entry from such attributes. I'm pretty new to this and primarily using the python gremlin client.

Here is a example about my case:

There is one vertex have an attribute called comments which have 3 values ["A", "B", "C"]. I want to update the value "C" to "D".

The only way I found is first delete all values and replace it with "A"

g.V(_id).property(Cardinality.single,"comments",'A').next()

Then add other values

g.V(_id).property(Cardinality.set_,"comments",'B').next()
g.V(_id).property(Cardinality.set_,"comments",'D').next()

I wounder if there is any other solutions to this. Thanks in advance.


Solution

  • You can remove an individual value from a set. Here is an example using the Gremlin Console where a set with three values is created and then the value 2 is removed from the set.

    gremlin> g.addV('test').property(set,'myset',1).property(set,'myset',2).property(set,'myset',3)
    ==>v[61371]
    
    gremlin> g.V().hasLabel('test').properties()
    ==>vp[myset->1]
    ==>vp[myset->2]
    ==>vp[myset->3]
    
    gremlin> g.V().hasLabel('test').properties('myset').hasValue(2)
    ==>vp[myset->2]
    
    gremlin> g.V().hasLabel('test').properties('myset').hasValue(2).drop()
    gremlin> g.V().hasLabel('test').properties()
    ==>vp[myset->1]
    ==>vp[myset->3]