cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

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

jake1
Node
MATCH (p)-[:HAS_CATEGORY]->(c:ProductCategory)
WHERE p.accountGUID = 'xxxxxxxxxx' AND NOT c.id 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!

1 REPLY 1

anthapu
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(c.id) as categories
WHERE none( x in categories WHERE x in ['76','1330', '65','1402', '1152','64','59'] )
return p