How to update 10 users as winners in backend?

Viewed 77

I have a usecase where I have to generate 10 winners out of 100 participants and update them in janusgraph. I have generated winners using math.ceil(math.random()) method and maintained their Id's in an array(say winners[10]).This winners[10] array is sent as a body and game I'd as a query parameter from front end. It is a post end point. I just need to add 500 points to the winners and retrieve their data. So what I have tried is

g.V().hasLabel('Game').has('active', true).
    as('game').
  outE('participated').inV().hasLabel('User').
  has('userdId', id).as('winner').
  addE('won').property('points', 500).
  to('game').
    select('winner').
  valueMap()

The above query executes for only one user. I want to make my query work for all the users. I have done some research on repeat(),loop(),iterate() steps but strucked with no option.And the result should be an array with 10 winners data.

Thanks in advance!

1 Answers

You can filter the vertices by multiple ids by using within:

g.V().hasLabel('Game').has('active', true).
    as('game').
  outE('participated').inV().hasLabel('User').
  has('userdId', within(1, 2, 3)).as('winner').
  addE('won').property('points', 500).
  to('game').
    select('winner').
  valueMap()

example: https://gremlify.com/9j071eajda4

Related