简体   繁体   中英

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 .

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM