Match a node only if ALL specific connected nodes have a specific label

I think this is a newbie question but cannot sort it out.

Me unfinished query looks like this:

MATCH (manufacturer:Manufacturer)-[:HAS_BRAND]->(brand:Brand)
// Here I need something to filter manufacturers where ALL Brand nodes have the label Ready.
// If at least one 'Brand' node is not 'Ready' then don't return those manufacturers.
RETURN DISTINCT manufacturer


We can do this with pattern comprehensions (which let us get the results of a MATCH in a list) and the all() list predicate:

MATCH (manufacturer:Manufacturer)
WHERE all(brand in [(manufacturer)-[:HAS_BRAND]->(brand) | brand] WHERE brand:Ready)
RETURN manufacturer
1 Like


I would like to extend my question.

I want to check 2 fields together simultaneously such as

MATCH (manufacturer:Manufacturer)
WHERE all(brand in [(manufacturer)-[:HAS_BRAND]->(brand)<-[:HAS_PART]-(part2), (brand)<-[:HAS_PART]-(part1) | [part1, part2]] WHERE part1:Ready AND part2:Ready)
RETURN manufacturer

The above doesn't really work as I am getting this error

Invalid input '|': expected whitespace, comment, a relationship pattern, '.', node labels, '[', '^', '*', '/', '%', '+', '-', "=~", IN, STARTS, ENDS, CONTAINS, IS, '=', '~', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ']' 

Basically the issue is contructing this array when it is required to do more than 1 match

[(manufacturer)-[:HAS_BRAND]->(brand)<-[:HAS_PART]-(part2), (brand)<-[:HAS_PART]-(part1) | [part1, part2]]


I found a long workaround

MATCH (manufacturer:Manufacturer)

WITH manufacturer,
[[(manufacturer)-[:HAS_BRAND]->(brand)<-[:HAS_PART]-(part2) | part2],[(manufacturer)-[:HAS_BRAND]->(brand)<-[:HAS_PART]-(part1) | part1]] as transposedList

UNWIND range(0,size(transposedList[0])-1) as idx
WITH [transposedList[0][idx],transposedList[1][idx]] as adjustedSeries , manufacturer

WITH collect(adjustedSeries) as adjustedList, manufacturer