Search code examples
titangremlintinkerpoptinkerpop3

Add multiple properties during edge creation in gremlin


I have used this query

g.V().has('empId','123').as('a').V().has('deptId','567').addE('worksAt').properties('startedOn','17/15/07','title','manager','pay',15000) 

which doesn't work.

Adding a single property works with a .property step

g.V().has('empId','123').as('a').V().has('deptId','567').addE('worksAt').property('startedOn','17/15/07') 

Solution

  • Instead of specifying all properties in one property-step, you can simply concatenate multiple property-steps:

    g.V().has('empId','123').as('a').V().has('deptId','567').addE('worksAt').
        property('startedOn','17/15/07').property('title','manager').property('pay',15000)
    

    Your query doesn't specify which vertices should be connected by the edge. When you want the edge to go out from the vertex with the empId 123, then you have to insert a from:

    g.V().has('empId','123').as('a').V().has('deptId','567').addE('worksAt').from('a').
        property('startedOn','17/15/07').property('title','manager').property('pay',15000)
    

    See the addEdge-step for more information.