Neo4j,密码 - 如何在其属性中 return 节点度数?

Neo4j, cypher - how to return node degree in its properties?

我现在使用的是这个查询:

MATCH (Parent)-[R]-(Child) WHERE ID(Parent)=$parentId
CALL {
    WITH Child
    RETURN apoc.node.degree(Child) as ChildDegree
}
RETURN Parent, Child, R, ChildDegree
LIMIT $limit

当前的解决方案效果很好,但我目前正在重建我们的后端,我想知道是否有可能以某种方式将节点度“注入”到所有节点的属性中?

我所说的属性是指这个对象:

这会大大简化后端,因为我在每个查询中都使用这个度数计数。

好的,您可以使用以下方法将您的节点与包含其度数的对象合并:

MATCH (Parent)-[R]-(Child) WHERE ID(Parent)=268
RETURN Parent, apoc.map.merge(Child, {degree: apoc.node.degree(Child)}) as Child, R
LIMIT 100

您可以 return 添加度数的地图投影:

MATCH (Parent)-[R]-(Child) WHERE ID(Parent)=268
RETURN Parent, Child{.*, degree: apoc.node.degree(Child) } as Child, R
LIMIT 100