Neo4j,获取一组节点之间的所有关系 [英] Neo4j, get all relationships between a set of nodes

查看:1520
本文介绍了Neo4j,获取一组节点之间的所有关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,该查询基于属性获取节点

I've a query that fetches nodes based on a property

MATCH (c { type: 'sometype' })
WITH c LIMIT 100
RETURN c

我想要的就是还获取结果集中节点之间的所有关系,在IRC上有人告诉我使用:

all I want is to also fetch all the relations between nodes in the resultset, on IRC someone told me to use:

MATCH (c { type: 'sometype'])
WITH c LIMIT 100
OPTIONAL MATCH (c)-[r]-()
RETURN c, r

但是这将包括从节点c到结果集之外的节点的关系(在我的情况下(数十万个关系)可能会产生非常大的无用的结果集或性能问题)

but that will include relationships from node c to nodes outside the resultset which in my case (some hundred thousand relationships) could create very big useless resultset or performance issues)

有什么方法可以实现?

推荐答案

alex

查询此问题的另一种方法:

Another way to approach this is this query:

MATCH (c {type : 'sometype'})-[r:*0..1]-(d {type : 'sometype'})
WITH c, collect(r) as rs
RETURN c, rs

这允许不存在此类关系的情况.

This allows for the case where there are no relationships of this sort.

恩典与和平,

吉姆

这篇关于Neo4j,获取一组节点之间的所有关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆