I want to query my Neo4j database and return multiple of the variables that I MATCH
. Unfortunately, whenever I try this, I receive an error. I did a bit of research online and someone mentioned that returning multiple variables returns them as different columns rather than adding rows to the records. Or something like that. Since my two variables are of the same type, I do want them to be added as rows to the same array of records.
How do I do that?
Here's my Cypher Query, encapsulated in a JavaScript function for use in my Node.js server.
function getMyEvents(tx, userID) {
return tx.run("MATCH (self:USER {userID: $userID})" +
"MATCH (self)-[h:HOST]->(hostingEvents:EVENT) " +
"MATCH (self)-[a:ATTENDING]-(attendingEvents:EVENT) " +
"RETURN attendingEvents, hostingEvents",
{"userID": userID})
}
I want both attendingEvents
and hostingEvents
to be returned as items in the same array / rows in the same record. Not as different columns or whatever was meant by the comments I encountered.
If I read your question correctly then what you want is to have match both the HOST
and the ATTENDING
relationship between self
and the :EVENT
?
Then you can match multiple relationship types using |
, giving you the Cypher
MATCH (self:USER {userID: $userID})
MATCH (self)-[:HOST|:ATTENDING]->(event:EVENT)
RETURN event
Note that I assume that both relationships have the same direction, if not then you can remove the >
from the pattern.