Consider instagram feed scenario. I want to get all the posts 'posted' by the people I follow. For each of these posts I want to know whether I have liked it or not and also know which of the other people I follow have liked it (if any). What is the best solution to get this in gremlin (possibly avoiding duplication)?
The following just gives the posts 'posted' by USER 2. How to get other information in the same query?
g.V().has('ID','USER 2').out('posted')
When you ask questions about Gremlin, especially one of this complexity, it is always best to include a Gremlin script that provides some sample data, like this:
As for the answer, I would probably do something like this:
You find the user and get their followers holding them in a list with
aggregate()
. Then you find their posts without('posted')
. To get yourMap
structure for your output you cangroup()
on those "posts". The secondby()
modulator usesproject()
to build your innerMap
and basically makes two traversals, where the first uses zero or one to represent your boolean value by doing acount()
and the second goes back to the "followers" list we aggregated earlier to filter for those. Note the important use offold()
at the end there to reduce the result of that inner traversal to a list.