简体   繁体   English

Neo4j Cypher 和嵌套的 WHERE 条件

[英]Neo4j Cypher and nested WHERE condition

I'm trying to create the following Cypher query:我正在尝试创建以下 Cypher 查询:

MATCH (p:Permission) 
WHERE NOT ((p)<-[:HAS|:CONTAINS*1..2]-(u:User) WHERE u.id = {userId}) AND p.minUserReputation <= {minUserReputation} 
RETURN p

I need to return all of the Permissions that are currently not assigned ( NOT ((p)<-[:HAS|:CONTAINS*1..2]-(u:User) ) to User(with u.id = {userId} ) and filtered by min reputation value ( p.minUserReputation <= {minUserReputation} )我需要将当前未分配的所有权限( NOT ((p)<-[:HAS|:CONTAINS*1..2]-(u:User) )返回给用户(使用u.id = {userId} ) 并按最小信誉值过滤 ( p.minUserReputation <= {minUserReputation} )

Currently, this query fails with the following Cypher error:目前,此查询失败并显示以下 Cypher 错误:

Error executing Cypher; Code: Neo.ClientError.Statement.SyntaxError; Description: Variable `u` not defined

Please help to fix this query.请帮助修复此查询。 Thanks!谢谢!

Since WHERE <pattern> and WHERE EXISTS(<pattern>) doesn't allow additional WHERE clauses on the pattern, it's best to match on the user first, allowing you to use your WHERE clause, then include the variable for that user in your predicate:由于WHERE <pattern>WHERE EXISTS(<pattern>)不允许在模式上有额外的 WHERE 子句,最好先匹配用户,允许您使用您的 WHERE 子句,然后将该用户的变量包含在您的谓词:

MATCH (u:User)
WHERE u.id = {userId}
MATCH (p:Permission)
WHERE p.minUserReputation <= {minUserReputation} 
AND NOT (p)<-[:HAS|:CONTAINS*1..2]-(u) 
RETURN p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM