In Neo4j, I have about a thousand nodes labelled Person
, and they all have outbound connections to about 200 nodes that are, let's say, Place
. Each person connects to many places.
I want to add a property to Person
nodes that shows its degree of separation from a Person
node with the name "Mary", regardless of the arrow direction (otherwise the people would not be able to get to another person because the arrow just points at the places they go to).
I used this code:
MATCH (mary:Person {name: 'Mary'})
MATCH (n:Person)
WHERE n <> mary
SET n.distance_to_mary = shortestPath((n)-[*]-(mary))
However, after I run it, I get "No changes, no records."
What did I do wrong? I run a code to set number of neighbors to this dataset before and it worked just fine. Thank you everyone.
A property cannot have a path value, so your query should have gotten an error.
You should use the LENGTH of the path instead:
MATCH (mary:Person {name: 'Mary'}), (n:Person)
WHERE n <> mary
SET n.distance_to_mary = LENGTH(shortestPath((n)-[*]-(mary)))