所以我研究了 neo4j,我可能会在即将到来的项目中使用它,因为它的数据模型可能非常适合我的项目。我查看了文档,但我仍然需要这个问题的答案:
我可以将关系设置为单向吗?
看来 Neo4j 的人很喜欢电影,所以我们继续吧。如果我有这样的图表:
Actor A -> [:Acts in] -> Movie B
那么方向就很明显了,因为节点的类型不同。
但我喜欢恐怖片所以...
Person A -> [:wants_to_kill] -> Person B
我需要这种关系是单向的,所以如果我查询“A 想要杀死谁?”如果我查询“B 想要杀死谁?”,我就会得到 B。我什么也没得到。
有时我仍然需要两个方向的关系
Like:
Person A <-[:has_met] -> Person B
...这是显而易见的。
文档说:
Relationships are equally well traversed in either direction. This means that there is
no need to add duplicate relationships in the opposite direction (with regard to
traversal or performance).
While relationships always have a direction, you can ignore the direction where it is
not useful in your application.
所以文档说,关系默认有一个方向,如果我愿意,我可以忽略它。
现在事情变得复杂了:
考虑下图(并注意箭头)
Person A <- [:wants_to_kill] -> Person B
Person B -> [:wants_to_kill] -> Person C
Person C -> [:wants_to_kill] -> Person A
如果我忽略所有人的指示[:wants_to_kill]
我得到错误的结果
对于“A / C 想要杀死谁?”
如果我知道必须忽略哪些,我就不会进行查询。
那么我可以以某种方式将关系设置为双向关系(在创建关系时),还是应该用两种关系(人 A 和 B 之间)对此进行建模?