Search code examples
neo4jcypherneo4j-apoc

How to combine two or more neo4j cypher result columns


Can I combine multiple neo4j cypher result columns into one array? The use case is I have a query that return an array of multiple columns:

......
RETURN a AS post, b AS author, c AS comment

Cypher returns this as three distinct sets of arrays a,b and c. Though these are connected data I only have a column view of each. I can use

result.records[i].get('post') 
result.records[i].get('author') 
result.records[i].get('comment')

but I can't assume that 'author' in [i] is the author of post[i]. So I need to have a RETURN where a, b and c is in row[i]..which means collapsing all three columns into one. So I want my resultArray to look like this:

 resultArray: [{a,b,c},{a,b,c},....]

where result.records[0] = {a,b,c}.

I hope I was able to explain the use case, any help would be appreciated.


Solution

  • You can combine multiple fields as follows:

    RETURN {post: a, author: b, comment: c}