mooncloud3
mooncloud3

Reputation: 21

How to properly use MATCH inside UNWIND for a Nebula query

I’m currently working with the Nebula graph database for the first time and I’m running into some issues with a query. In terms of the schema, I have “Person” nodes, which have a “name” property, as well as Location nodes also with a name property. These node types can be connected by a relationship edge, called HAS_LIVED (to signify whether a person has lived in a certain location). Now for the query, I have a list of names (strings). The query looks like:

UNWIND [“Anna”, “Emma”, “Zach”] AS n
MATCH (p:Person {name: n})-[:HAS_LIVED]->(loc)
RETURN loc.Location.name

This should return a list of three places, i.e. [“London”, “Paris”, “Berlin”]. However, I am getting nothing as a result from the query. When I get rid of the UNWIND and write three separate MATCH queries with each name, it works individually. Not sure why.

Upvotes: 2

Views: 161

Answers (2)

egasimov
egasimov

Reputation: 41

One more solution to the problem is to use "IN" operator in the "WHERE".

MATCH (p:Person)-[:HAS_LIVED]->(loc)
where p.name IN [“Anna”, “Emma”, “Zach”]
RETURN loc.Location.name

Upvotes: 0

jose_bacoy
jose_bacoy

Reputation: 12704

Try this instead. It is using "where" clause.

UNWIND [“Anna”, “Emma”, “Zach”] AS n
MATCH (p:Person)-[:HAS_LIVED]->(loc)
where p.name = n
RETURN loc.Location.name

Upvotes: 0

Related Questions