Search code examples
gremlin

Gremlin parameterised query for addV() with unbounded number of property


How do I write a parameterised gremlin query to add a vertex with many number of properties. I want to parameterise the property in such a way that.. I should be able to pass the properties in a Map and the query to read and insert all those into the vertex. Is this possible at all?


Solution

  • It is only possible with a script where you construct the traversal on the remote side and, then, only possible for graph systems that support scripts in that way (e.g. wouldn't work on CosmosDB). You would just send your script as the following where m is your Map:

    t = g.addV()
    m.each{k,v -> t= t.property(k,v)]
    t