简体   繁体   English

Neo4j, cypher - 如何在其属性中返回节点度数?

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

What I am using now is this query:我现在使用的是这个查询:

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

Current solution works great but I am currently rebuilding our backend and I was wondering if it is possible to just "inject" node degree into all of the nodes' properties somehow?当前的解决方案效果很好,但我目前正在重建我们的后端,我想知道是否有可能以某种方式将节点度“注入”到所有节点的属性中?

By properties I mean this object:我所说的属性是指这个 object:

在此处输入图像描述

This would simplify backend a lot as I am using this degree counting in every query.这将大大简化后端,因为我在每个查询中都使用这个度数计数。

Ok so you can merge your node with an object containing its degree using:好的,您可以使用以下方法将您的节点与包含其度数的 object 合并:

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

You can return a map projection with its degree added:您可以返回 map 投影,并添加其度数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM