0

I'm new to Gremlin. Struggling to get this one right. Any help would be really appreciated.

I have the Comments(C), Plans(P) and Users(U) enter code here data in below format.

C3 - CommentsOn -> P1
C2 - CommentsOn -> P1
C1 - CommentsOn -> P1

U2 - Likes -> C3
U4 - Likes -> C3
U1 - Likes -> C1
U1 - Likes -> C2

Now I need to get the data in below format

[
 {
  "Comment": C3,
  "LikedBy": [{U2},{U4}]
 },
 {
  "Comment": C2,
  "LikedBy": [{U1}]
 },
 {
  "Comment": C1,
  "LikedBy": [{U1}]
 }
]

Meaning, I need to get the list of comments and their corresponding likes.

user1472423
  • 101
  • 1
  • 12

1 Answers1

1

In the future, you might consider including a Gremlin script that creates a small sample dataset so that you can get a tested answer (example). Anyway, the answer here is to use project():

g.V().hasLabel('Comment').
  project('Comment','LikedBy').
    by().
    by(__.in('Likes').fold())
stephen mallette
  • 45,298
  • 5
  • 67
  • 135