简体   繁体   English

过滤与某个节点没有关系的Neo4j节点

[英]Filter Neo4j nodes that have no relationship with a certain node

I want to find all Foos that are not yet associated with my Bar. 我想查找尚未与我的酒吧关联的所有Foos。 I use neo4j.rb (4.1.2) and Rails (4.2). 我使用neo4j.rb(4.1.2)和Rails(4.2)。 The code I use now, that produces the right output but feels unoptimal is: 我现在使用的代码可以产生正确的输出,但是感觉不是最佳的:

@foos = Foo.all.find_all do |foo|
  foo.bars.rels_to(current_bar).count == 0
end 

Is there a better way of doing this with Cypher? 使用Cypher有更好的方法吗?

Here is one way to do this in Cypher. 这是在Cypher中执行此操作的一种方法。 I assume you are only interested in direct relationships, and that Bar nodes are identified by an id property. 我假设您只对直接关系感兴趣,并且Bar节点由id属性标识。

MATCH (b:Bar), (f:Foo)
WHERE b.id = 123 AND NOT (b)--(f)
RETURN b, COLLECT(f);

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

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