0

How do we write gremlin update/modify query in node.js ?

I want to update particular field and save the same and do not modify other fields which are not edited.

I have a table called "org" and it has some properties like name, id, label.
How can we modify particular property or all the properties depends on the put body request ? using gremlin query

userrj_vj_051620
  • 147
  • 2
  • 12
  • I have a table called "org" and it has some properties like name, id, label. How can we modify particular property or all the properties depends on the put body request ? using gremlin query – userrj_vj_051620 Mar 04 '21 at 08:02

1 Answers1

0

Any property can be updated as follows (assuming it is a single value and not a set)

g.V('some-id').
  property(Cardinality.single,'my-property',new-value).
  iterate()

UPDATED: If you need to update the contents of multiple properties you can just chain the property steps together.

g.V('some-id').
  property(Cardinality.single,'p1',new-value).
  property(Cardinality.single,'p2',new-value).  
  property(Cardinality.single,'p3',new-value).  
  property(Cardinality.single,'p4',new-value).iterate()

UPDATED again

If you only want to set a property value if the property already exists you can check for its existence using a 'has' step as shown below.

g.V('some-id').
  has('p1').
  property(Cardinality.single,'p1',new-value)

If you want to do this for more than one property you can use optional steps as one way to do multiple of these checks.

g.V('some-id').
  optional(has('p1').
    property(Cardinality.single,'p1',new-value)).
  optional(has('p2').
    property(Cardinality.single,'p2',new-value)).

Some additional information can be found at [1] and [2]

[1] http://www.kelvinlawrence.net/book/PracticalGremlin.html#addnodes

[2] https://tinkerpop.apache.org/docs/current/reference/#addproperty-step

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38