Request neo4j cypher request with collect

In a cypher query I have multiple results that I am getting now using a collection, how can I order by collecting a property in a cypher?

MATCH(u:User) 
WITH COLLECT({name:u.name,date:u.date}) AS userinfo 
RETURN userinfo

      

OR in case of combining several collections

MATCH(u:User)-[r:CreatedBy]->(p:Project) 
WITH COLLECT({name:p.name,date:p.date}) AS info 
MATCH(i:Institue)-[owner:Owner]->(i:Institute) 
WITH COLLECT({instituteName:i.name,date:i.date}) AS instituteinfo,info 
WITH COLLECT(instituteinfo + info) AS alldata 
RETURN alldata

      

+3


source to share


1 answer


You just need to order custom nodes by your chosen attribute prior to collecting them. Something like that..,

MATCH(u:User)
WITH u
ORDER BY u.name
WITH COLLECT({name:u.name,date:u.date}) AS userinfo 
RETURN userinfo

      



Or, if you want to combine multiple collections and create a single ordered collection, you can recompile them something like this ...

MATCH(u:User)-[r:CreatedBy]->(p:Project) 
WITH COLLECT({name:p.name, date:p.date}) AS info 
MATCH(i:Institue)-[owner:Owner]->(i:Institute) 
WITH COLLECT({instituteName:i.name, date:i.date}) AS instituteinfo,info 
WITH instituteinfo + info AS alldata 
UNWIND alldata as node
WITH node
ORDER BY node.name
WITH COLLECT (DISTINCT node) as alldata
RETURN alldata

      

+1


source







All Articles