How to get degree of a node while filtering using MATCH in neo4j

前端 未结 2 412
谎友^
谎友^ 2021-01-13 21:47

I have a graph with 4 levels. While filtering using MATCH, how can i get the \"degree\" of a node? I am always getting a \"degree\" of 1.

Here is my que

相关标签:
2条回答
  • 2021-01-13 22:19

    More information would be helpful, but in general you can get the degree of a node by doing something like:

    MATCH (n)--(other)
    WHERE n.id = {id}
    RETURN count(other)
    

    If you want to find degrees for many nodes you can leave out the WHERE or specify a more generic query:

    MATCH (n)--(other)
    WHERE n.property = {value}
    RETURN n, count(other)
    
    0 讨论(0)
  • 2021-01-13 22:28

    You are getting count of 1 because you aggregated over all 3, start-node, end-node, and all relationships in the path.

    This is the most efficient way.

    MATCH (k)
    WITH k, size((k)-[:TYPE]->()) as degree
    WHERE k.Value='30 ' AND degree > 1
    MATCH (k)-[r:TYPE]->(n:ABC)
    RETURN n,r,k,degree;
    
    0 讨论(0)
提交回复
热议问题