Showing results for 
Search instead for 
Did you mean: 

Is filtering with a WHERE NOT IN on a collection like this possible? Not seeing expected results even on simple queries

MATCH (p)-[:HAS_CATEGORY]->(c:ProductCategory)
WHERE p.accountGUID = 'xxxxxxxxxx' AND NOT IN ['76','1330', '65','1402', '1152','64','59']
return p

Products are being returned from the above query that DO have relationships with categories from the collection that should be filtered out. Am I misunderstanding how the WHERE NOT IN clause works with respect to relations?

Any help or explanation is appreciated! Thank you!


Graph Fellow

Could it be that p is associated with other categories that are not in the list. In that case this would return that p even though it might be associated with the categories provided in the list as there is a path.

Ex: Say this is the data

(p)-[:HAS_CATEGORY]->(c:ProductCategory {id:'76')
(p)-[:HAS_CATEGORY]->(c:ProductCategory (id:'75')

In this case there is MATCH for category id 75 that is returned. So, you will get that p node returned.

If you don't want any p returned if that is associated with the specified categories irrespective of other connections then query should be like this

MATCH (p)-[:HAS_CATEGORY]->(c:ProductCategory)
WHERE p.accountGUID = '1234'
WITH p, collect( as categories
WHERE none( x in categories WHERE x in ['76','1330', '65','1402', '1152','64','59'] )
return p