I have the next graph:
Theme Contains multiple Stories. Theme and Story are graph nodes, connected via Contains relation.
Each node has property name.
I would like to write a Cypher query so it returns the concatenated string from names.
E.g. Theme.name = "theme name", Story1.name = "s1 name", Story2.name = "s2 name". Query result expected: "theme name s1 name s2 name".
How that can be done?
When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.
The CALL clause is used to call a procedure deployed in the database.
The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope. Any variables not included in the WITH clause are not carried over to the rest of the query.
Administration clauses These comprise clauses used to manage databases, schema and security; further details can found in Database management and Access control. Clause. Description. CREATE | DROP | START | STOP DATABASE. Create, drop, start or stop a database.
You have a couple of choices, using either REDUCE or apoc.text.join (from the apoc procedures in 3.x)
something like this -
MATCH (t:Theme)-[:Contains]->(s:Story)
RETURN REDUCE(result=t.name, s in collect(s.name) | result+" "+s)
Or using APOC
MATCH (t:Theme)-[:Contains]->(s:Story)
RETURN apoc.text.join(t.name+collect(s.name)," ")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With