This bug has troubled me for a long time, and there are very few replies on the Internet, so I will record it specially. Those questions about py2neo:
The match statement cannot be executed due to different versions of neo4j
and py2neo
This code doesn't work on my computer:
zzu1 = graph.nodes.match("school", name="zzu").first()
Modify it to this:
zzu1 = graph.nodes.match('school').where("_.name='zzu'").first()
will work.
There is also an example of match
, I don't know why it works. This example implements the same function as the above example, and both find the node whose name
attribute value is zzu
in the label
tag:
zzu2 = graph.run("MATCH(a:school) WHERE a.name = 'zzu' RETURN a").data()
Some people say that the use of variables in match
may also cause inexplicable bugs. Maybe because I didn't use match
, the code in the following format did not report an error: (that is, the normal use of format
for strings)
verb = "located"
noun = "zzu"
city1 = graph.run("match(a:school)-[r:{v}]->(b:city) WHERE a.name = '{n}' RETURN b".format(v=verb, n=noun)).data()
The problem someone has encountered is that the string contains an illegal symbol, aka invalid input
. I had a similar problem with this code of mine:
city1 = graph.run("match(a:school)-[r:is located in]->(b:city) WHERE a.name = 'zzu' RETURN b").data()
is located in
is the error point, which is obviously a space problem. But I still can't solve it after entering the escape character '\0'
for spaces. In desperation, I had to rename this relationship to located
, which solved the problem:
city1 = graph.run("match(a:school)-[r:located]->(b:city) WHERE a.name = 'zzu' RETURN b").data()