I'm having following vertex and edges.
User1 -> create ->Post1
Post1 -> postedOnWall -> User2
User2 -> create ->Comment1
Comment1 -> PostedOnComment -> Post1
User3 -> create -> Comment2
Comment2 -> PostedOnComment -> Post1
User1 created Post1 and Posted it on User2's Wall. Now User2 Created a Comment and posted it on Post1. and User3 also posted comment on same post.
How can I get the list of all post on user's wall along with all comments in each posts.
I'm getting list of post by following query :
g.v(512).in('label','WallPost').sort{it.PostedTime}.reverse().().as('postInfo')[0..10].in('label','Comment').().as('comment').select{it}{it}
Am not able to find any way to get list of comments on each post.
Using the select()
step gets you pretty close, but I think a transform()
might be what you're looking for. I've posted a full Gremlin Console session result in a gist, but the key part is this:
gremlin> g.V('name','user2').in('PostedOnWall').sort{ a, b -> b.PostedTime <=> a.PostedTime }._().transform{ [post: it.msg, comments: it.in('PostedOnComment').msg.toList()] }
==>{post=what is for dinner?, comments=[tacos]}
==>{post=hello, comments=[buenos dias, bongiorno]}