vishal patel
vishal patel

Reputation: 832

Neo4j how to orderBy collection

I have node structure where i have parent nodes and child nodes. Child nodes have :has relation ship with parent node.

My current query is

 Match (p:Parent)
 Where Id(p) = 2
 WITH p
 Match (c:CHILD)
 WHERE (p)-[:has]-(c)
 return p,collect(DISTINCT c) as child[0..9]

Now my problem is all child nodes are arranged by their id's and i am only able to receive first 9 childs ordered by their id.

How can i specify order of childs?

Upvotes: 2

Views: 37

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41706

Try this:

You can use an in-between WITH to order your nodes. Btw. you should have consistent label spelling!

 Match (p:Parent)-[:has]-(c:CHILD)
 Where Id(p) = 2
 WITH p, c order by id(c) asc
 return p,collect(DISTINCT c)[0..9] as child

Upvotes: 2

Related Questions