Reputation: 495
Here SuperUser created Sunil. Sunil created ravi ... Divya created Ramya.
When I query like this
match (a:Login{Type:"SuperUser"})<-[:createdBy*0..5]-(m) return *
I am getting the same response as in the picture. But from the JSON I cant able to figure out who is created by whom. I need the response something like
{"n":{"id":"SuperUser","created":[{"id":"sunil","created":[{"id":"ravi","created":[{"id":"Prem"},{"id":"Divya","created":[{"id":"Ramya"}]}]}]}]}}
So that I can know who is created by whom. Thanks
Upvotes: 2
Views: 2642
Reputation: 2417
You need to specify that information explicitly in your return clause. Use this query.
MATCH (a:Login{Type:"SuperUser"})<-[:createdBy*0..5]-(m)
WITH collect(m) as source
WITH source, range(0, size(source)) AS index
UNWIND index as i
WITH source[i] as m
MATCH (m:Login)-[:createdBy]->(n:Login) RETURN m.Name as user, n.Name as CreatedBy
You can use ORDER BY clause to group the data as well.
Upvotes: 1