In Cypher Neo4j Graph Database, I want to get the results of query in strings without square brackets. Every time I retrieve information from nodes properties, I get the results in strings as expected but when I retrieve information from relationships, It displayed inside square brackets.
MATCH (m:Movie {title:"The Matrix"})<-[r:ACTED_IN]-() return r.roles;
Results:
[Agent Smith]
[Morpheus]
[Trinity]
[Neo]
The reason you get the square brackets is that the roles
property of the ACTED_IN
relationships is a list.
You can use UNWIND
to expand a list (including lists of one-element) to rows:
MATCH (m:Movie {title:"The Matrix"})<-[r:ACTED_IN]-()
UNWIND r.roles AS roles
RETURN roles
If I run it on the Matrix dataset provided in this tutorial, I get:
╒═══════════╕
│roles │
╞═══════════╡
│Agent Smith│
├───────────┤
│Emil │
├───────────┤
│Trinity │
├───────────┤
│Morpheus │
├───────────┤
│Neo │
└───────────┘