假设有一个简单的图表如下, (City {name:gotham})-[:LOCATED]-(Tower {name:abc})-[:LOCATED]-(Bank:{name:CityBank})(City {name:gotham})-[:LOCATED]-(Cinema {name:MainHall})(City {name:gotham})-[:LOCATED]-(Bank {name:ComBank}) 我怎样才
(City {name:gotham})<-[:LOCATED]-(Tower {name:abc})<-[:LOCATED]-(Bank:{name:CityBank}) (City {name:gotham})<-[:LOCATED]-(Cinema {name:MainHall}) (City {name:gotham})<-[:LOCATED]-(Bank {name:ComBank})
我怎样才能在Neo4j数据库(包括CityBank和comBank)中找到名为Gotham的所有银行?我尝试了以下模式,它返回了位于City的所有节点,名为gotham(包括Cinema)
MATCH (City{name:'Gotham'})<--(Bank) RETURN Bank假设你错误输入了查询,那么什么不起作用?
MATCH (:City{name:'Gotham'})<--(bank:Bank) RETURN bank
应该工作正常.
完全错误的打字,应该读(孤独的星指示,任何类型的所有关系,任何长度路径):
MATCH (:City{name:'Gotham'})<-[*]-(bank:Bank) RETURN bank
更好的是:
MATCH (:City{name:'Gotham'})<-[:LOCATED*1..2]-(bank:Bank) RETURN bank
所以只能遍历LOCATED关系.您可以调整* 1..2(匹配长度为1到2的路径)以满足路径长度要求(例如,如果添加了街道或块节点,则可能需要匹配长度为3 * 1的路径. )