Search code examples
gremlinazure-cosmosdb-gremlinapi

can we add two vertices and an edge between them using a single gremlin query?


I am looking for a single gremlin query that can add two vertices and an edge between them. Right now I am just able to insert 2 vertices using two gremlin queries and then inserting the edge between them using one more gremlin query. I want to do all of this using a single gremlin query.


Solution

  • You can add vertices and edges in a single query. A common way to do this is something like:

    g.addV('Person').property('name','Fred Weasley').as('a').
      addV('Person').property('name','George Weasley').as('b').
      addE('Brother').from('a').to('b')