假设我的Neo4J数据库中有3部电影:
CREATE (interpreter:Movie {title: 'The Interpreter', year : 2005})
CREATE (dogville:Movie {title: 'Dogville', year : 2003})
CREATE (railwayMan:Movie {title: 'The Railway Man', year : 2013})
还有用户:
CREATE (maciej:Person {name: 'Maciej Ziarko', birthYear: 1989})
谁评价电影:
CREATE (maciej)-[:RATED {stars : 4, comment : "I liked that movie!" }]->(interpreter);
使用Cypher
很容易找到特定用户评分的电影MATCH (person:Person)-[:RATED]->(movie:Movie)
WHERE person.name = 'Maciej Ziarko'
RETURN movie.title
结果:
+-------------------+
| movie.title |
+-------------------+
| "The Interpreter" |
+-------------------+
1 row
但是如何才能找到特定用户评价的电影不?
答案 0 :(得分:4)
您可以使用以下内容:
MATCH (m:Movie) WHERE NOT (m)<-[:RATED]-() return m.title
在WHERE
中,您可以使用NOT
过滤非现有路径,请参阅http://docs.neo4j.org/chunked/milestone/query-where.html#where-filter-on-patterns-using-not
答案 1 :(得分:0)
阅读Stefan的回答后我做了什么:
MATCH (movie:Movie), (person:Person)
WHERE person.name = 'Maciej Ziarko'
AND (NOT (movie:Movie)<-[:RATED]-(person:Person))
RETURN movie.title
结果:
+-------------------+
| movie.title |
+-------------------+
| "Dogville" |
| "The Railway Man" |
+-------------------+
2 rows