本文介绍了Neo4j双向关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Cypher在Neo4j中创建双向关系?我希望该关系是双向的,而不是在两个方向上都建立两个单向关系,例如:

Is there a way to create bidirectional relationship in Neo4j using Cypher? I would like the relationship to be bidirectional rather than making two unidirectional relationships in both directions For eg:

(A)<-[FRIEND]->(B)

而不是:

(A)-[FRIEND]->(B)
(A)<-[FRIEND]-(B)

先谢谢您了:)

推荐答案

不,没有. neo4j中的所有关系都有一个方向,在给定节点处开始和结束.

No, there isn't. All relationships in neo4j have a direction, starting and ending at a given node.

有少量解决方法.

  • 首先,正如您所建议的,我们可以有两种关系,一种从A到B,另一种从B到A.

  • Firstly, as you've suggested, we can either have two relationships, one going from A to B and the other from B to A.

或者,当编写我们的MATCH查询时,我们可以使用

Alternatively, when writing our MATCH query, we can specify to match patterns directionlessly, by using a query such as

MATCH (A)-[FRIEND]-(B) RETURN A, B

它不会在乎A是否是B的朋友,反之亦然,并且允许我们在建立关系时随意选择一个方向.

which will not care about whether A is friends with B or vice versa, and allows us to choose a direction arbitrarily when we create the relationship.

这篇关于Neo4j双向关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 14:20