Uttkarsh Jain
Uttkarsh Jain

Reputation: 228

Gremlin: Add an edge and drop an edge in single gremlin query

how to add an edge and dropping an edge to same vertex type in single gremlin query.

say we have two types of vertex types A --is--> B now i have vertex which is connected to some other vertex of B.

I want to update the A's vertex to some other vertex of B.

currently, i am dropping the current B vertex and then adding the new vertex .

Upvotes: 4

Views: 1465

Answers (1)

stephen mallette
stephen mallette

Reputation: 46206

You can do it in one traversal using a sideEffect():

gremlin> g.V().has('person','name','marko').as('m').
......1>   outE('knows').
......2>   filter(inV().has('person','name','vadas')).
......3>   sideEffect(drop()).
......4>   V().has('person','name','peter').
......5>   addE('knows').from('m')
==>e[13][1-knows->6]

At line 1 we basically identify the edge we want to get rid of (i.e. a "knows" edge from "marko" to "vadas") and we drop() that on line 3. At line 4 we lookup the vertex to whom we wish to connect "marko" to now and then add the edge at line 5.

Upvotes: 6

Related Questions