I have a "User" vertex having few users in it. I have an "Invitation" vertex which basically tells about an invitation a user has sent to another user. I have a "sentTo" edge connecting Invitation vertex with the user vertex(the user who is the recipient of the invitation). I have a "sentBy" edge connecting the Invitation vertex to the user vertex(the user who has sent the invitation). The sentBy edge has a "on" property which is a Date object. The sentBy edge also has "inviterCount" property, which is basically the invitation count(at that time of creation of sentBy edge) for that recipient user(the user who receives the invitations). For some reason I have the "on" property correctly set, but not the inviterCount. In order to set the inviterCount on a sentBy edge I need to first order the invitations sent to that user. I am able to order the sentBy edges by "on" date in ascending order which is a fairly straightforward gremlin query. I am struggling to update the inviterCount property which is basically the position of that user in the list of invitations. How do I know the position of an edge in a list of edges, and also set a property on that edge (inviterCount) within a query, for a given recipient of invitations?
g.addV('User').property('userId',1).property('name','Sam').as('u1')
.addV('User').property('userId',2).property('name','Ram').as('u2')
.addV('User').property('userId',3).property('name','Cam').as('u3')
.addV('User').property('userId',4).property('name','Nam').as('u4')
.addV('Invitation').property('invitationId',1).as('i1')
.addE('sentBy').property('on',new Date(1621047481204)).to('u1')
.select('i1').addE('sentTo').to('u4')
.addV('Invitation').property('invitationId',2).as('i2')
.addE('sentBy').property('on',new Date(1621047612262)).to('u2')
.select('i2').addE('sentTo').to('u4')
.addV('Invitation').property('invitationId',3).as('i3')
.addE('sentBy').property('on',new Date(1621047644430)).to('u3')
.select('i3').addE('sentTo').to('u4')
g.V().hasLabel('User').has('name','Nam').inE('sentTo').outV().outE('sentBy').order().by('on')
As I have stated earlier the sentBy edge has another property called inviterCount which needs to be set.
Edit I have read through sacks, but they don't help with what I need to do. For each traversal, the sack variable is reset and any operations on that sack will be carried across for that traversal. What I need is a counter which carries across traversals. In simpler words, I need an iteration counter. I need an 'i' in the basic for loop.
inE('sentBy')
and Nam, but in the data all of the edges connecting to Nam are of the forminE('sentTo')
. If I understand your explanation you may be able to use theindex
step. I can try to provide an example if you can clarify the way the edge labels and the query are supposed to be. - Kelvin Lawrence