本文介绍了Neo4j Cypher查询为null或IN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下密码查询:
MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User)
WHERE id(parentD) = {decisionId}
RETURN ru, u, childD
SKIP 0 LIMIT 100
Decision
实体可以属于0..N个Tenant
对象
Decision
entity can belong to 0..N Tenant
objects
@NodeEntity
public class Decision {
private final static String BELONGS_TO = "BELONGS_TO";
@Relationship(type = BELONGS_TO, direction = Relationship.OUTGOING)
private Set<Tenant> tenants = new HashSet<>();
....
}
我需要扩展上述Cypher查询,以返回所有childD
,其中parentD
和childD
不属于Tenant
的任何一个,也不属于Tenant
,且其ID在{tenantIds}
中提供.请帮助我进行此查询.
I need to extend the Cypher query above in order to return all childD
where parentD
and childD
not belong to any of Tenant
or belong to Tenant
with IDs provided in {tenantIds}
set. Please help me with this query.
推荐答案
密码是一种非常有表现力的语言,只需遵循您的文字要求即可.
Cypher is very expressive language, just follow your textual requirements...
MATCH (t:Tenant) WHERE ID(t) in {tenantIds}
WITH COLLECT(t) as tenants
MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User)
WHERE
id(parentD) = {decisionId}
AND
// not belong to any of Tenant or belong to Tenant
(not (parentD)-[:BELONGS_TO]-(:Tenant) OR any(t in tenants WHERE (parentD)-[:BELONGS_TO]-(t)))
AND
// not belong to any of Tenant or belong to Tenant
(not (childD)-[:BELONGS_TO]-(:Tenant) OR any(t in tenants WHERE (childD)-[:BELONGS_TO]-(t)))
RETURN ru, u, childD
SKIP 0 LIMIT 100
这篇关于Neo4j Cypher查询为null或IN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!