Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

71
Views
Cypher Neo4j Return Multiple Variables (node.js Driver)

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.

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.