英文:
Neo4j Cypher: Find isolated node
问题
我想找到不与其他节点连接的节点(如下图中的节点A和节点B)。
我尝试过的方法是:
MATCH (n:node) WHERE not ((n)<-[:connect]->(:node)) RETURN n
这似乎只返回了节点B。
如何可以检索到节点A和节点B?
提前感谢!
英文:
I want to find nodes that do not connect with other nodes. (node A and node B in the picture below)
What I have tried is
MATCH (n:node) WHERE not ((n)<-[:connect]->(:node)) RETURN n
which seems to return only B.
How can I retrieve both A and B?
Thank you in advance!
答案1
得分: 1
[UPDATED]
如果你只关心connect
关系,以下代码将有效:
MATCH (n:node)
WHERE SIZE([(n)-[:connect]-(m:node) WHERE n <> m|1]) = 0
RETURN n
但是,如果你想关注所有关系类型,那么请使用以下代码:
MATCH (n:node)
WHERE SIZE([(n)--(m:node) WHERE n <> m|1]) = 0
RETURN n
英文:
[UPDATED]
This will work if you only care about connect
relationships:
MATCH (n:node)
WHERE SIZE([(n)-[:connect]-(m:node) WHERE n <> m|1]) = 0
RETURN n
But if you want to pay attention to all relationship types, then use this:
MATCH (n:node)
WHERE SIZE([(n)--(m:node) WHERE n <> m|1]) = 0
RETURN n
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论