Neo4j - WHERE negation on path not working

MATCH (n:Owner),(v:Vehicles)
WHERE NOT (n)-[:OWNS]->(v)


MATCH (n:Owner),(v:Vehicles)
WHERE  (n)-[:OWNS]->(v)

is giving me the same result...What am I missing here?

Is there another relationship between Owner and Vehicle nodes?


Nope....not between Owner and Vehicles

On the other hand this works:

MATCH (n:Owner) MATCH (v:Vehicles)
WHERE NOT (n)-[:OWNS]-()

I think your StackOverflow question was answered, but I'll answer again here:

MATCH (n:Owner),(v:Vehicles) creates a cartesian product, so you will get rows for every possible combination of an :Owner node with a :Vehicles node. If you had 50 :Owner nodes and 20 :Vehicles nodes then this would produce 1000 rows for this cartesian product.

For each of those rows (each distinct combination of one of the :Owner nodes and one of the :Vehicles nodes) your WHERE clause would filter WHERE (or WHERE NOT) that specific owner for that row owns that specific vehicle for that row.

That is a completely different thing than filtering based upon whether or not an owner owns ANY vehicle.

And if that's the question you really intend to ask, then you need to change your query to avoid the cartesian product like so, and fit the pattern that you actually intend to include (or exclude):

MATCH (n:Owner)
WHERE NOT (n)-[:OWNS]-(:Vehicles)

Thanks I did miss the possibility of the Cartesian product....There use to be a warning when you do this I don't see that warning anymore maybe Neo4j should look at making it a standard warning.

I see the warning in my browser when I paste the query in, so as far as I can see the warnings are working fine.

Note that a cartesian product isn't necessarily wrong...there may be some queries where that's exactly the correct thing to do, so an error wouldn't make sense.

If the warning is not appearing for you, can you better describe how you're running this, and which version of the browser you're using?

I am using browser version 3.2.13. and the use is exactly as written or the variant MATCH( (n:Owner) Match (v:Vehicles) WHERE NOT (n)-[:OWNS]->(v) RETURN DISTINCT .....

That's an older browser version, there may have been a bug in that one where the warnings would not appear. I'm using browser version 3.2.18 (comes with Neo4j Desktop) and can see the warning icon come up in the query text area, just to the left of the query after pasting it in.

If you upgrade your browser (and/or upgrade your Neo4j version which should also come with an updated browser version) you should also be able to see the warnings show up.

Thanks Andrew...will do