【问题标题】:Cypher - Referencing a Node from a property on a referenceCypher - 从引用的属性中引用节点
【发布时间】:2013-05-19 20:35:20
【问题描述】:

给定一个图表,其中关系上的属性是节点的键,我如何返回关系属性引用的节点?

所以,给定图表:

Node(user1 { type: "user", uid: "u1", name: "test user" })
Node(user2 { type: "user", uid: "u2", name: "test user 2})
Node(cat1 { type: "category", cid: "c1", name: "Nice person"})

Rel( (user1)-[:SAYS { cid: "c1" }]->(user2) )

如何返回 cat1 节点以及给定 user1 的 user2 节点?

(例如,返回值将包括 cat1 的定义以及 user1 和 user2)。

逻辑起点是:

START user1 = node:auto_node_index(uid = "u1")
MATCH (user1)-[cat:SAYS]->(user2)
RETURN user1, cat, user2;

但我不知道从这里去哪里。

如果这变得太复杂,我总是可以将类别的属性放入关系中(显然),但这往往会驱使我使用辅助存储介质来存放类别定义(因为它们将成为孤立节点图表)。

谢谢! r/史蒂夫

【问题讨论】:

    标签: properties neo4j nodes cypher relationships


    【解决方案1】:

    嗯。实际上相当容易。输入问题让我更清楚地思考这个问题。这有效:

    START user1 = node:node_auto_index(uid = "u1"), c = node:node_auto_index(type = "category")
    MATCH (user1)<-[cat:SAYS]-(user2)
    WHERE c.cid = cred.cid
    RETURN user1, cat, user2, c;
    

    【讨论】:

    • 我想你会得到一个unknown identifier: cred--你的意思是cat吗?我对您为什么要以这种方式建模有点困惑。想详细说明您的用例吗?
    • 是的,这是一个错字。玩弄诸如 LinkedIn 的背书实现之类的东西。所以 user1 支持 user2 做某事。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2016-11-15
    • 2015-06-17
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多