SHARE
TWEET

Untitled

a guest Apr 19th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. **Basic Graph Operations with CYPHER**
  2.  
  3. **Counting the number of nodes**
  4. ```
  5. match (n:MyNode)
  6.  
  7. return count(n)
  8. ```
  9.  
  10. **Counting the number of edges**
  11.  
  12. ```
  13. match (n:MyNode)-[r]->()
  14.  
  15. return count(r)
  16. ```
  17.  
  18. **Finding leaf nodes:**
  19.  
  20. ```
  21. match (n:MyNode)-[r:TO]->(m)
  22.  
  23. where not ((m)-->())
  24.  
  25. return m
  26. ```
  27.  
  28. **Finding root nodes:**
  29.  
  30. ```
  31. match (m)-[r:TO]->(n:MyNode)
  32.  
  33. where not (()-->(m))
  34.  
  35. return m
  36. ```
  37.  
  38. **Finding triangles:**
  39.  
  40. ```
  41. match (a)-[:TO]->(b)-[:TO]->(c)-[:TO]->(a)
  42.  
  43. return distinct a, b, c
  44. ```
  45.  
  46. **Finding 2nd neighbors of D:**
  47. ```
  48. match (a)-[:TO*..2]-(b)
  49.  
  50. where a.Name='D'
  51.  
  52. return distinct a, b
  53. ```
  54.  
  55. **Finding the types of a node:**
  56.  
  57. ```
  58. match (n)
  59.  
  60. where n.Name = 'Afghanistan'
  61.  
  62. return labels(n)
  63. ```
  64. **Finding the label of an edge:**
  65. ```
  66. match (n {Name: 'Afghanistan'})<-[r]-()
  67.  
  68. return distinct type(r)
  69. ```
  70. **Finding all properties of a node:**
  71. ```
  72. match (n:Actor)
  73.  
  74. return * limit 20
  75. ```
  76. **Finding loops:**
  77. ```
  78. match (n)-[r]->(n)
  79.  
  80. return n, r limit 10
  81. ```
  82. **Finding multigraphs:**
  83. ```
  84. match (n)-[r1]->(m), (n)-[r2]-(m)
  85.  
  86. where r1 <> r2
  87.  
  88. return n, r1, r2, m limit 10
  89. ```
  90. **Finding the induced subgraph given a set of nodes:**
  91. ```
  92. match (n)-[r:TO]-(m)
  93.  
  94. where n.Name in ['A', 'B', 'C', 'D', 'E'] and m.Name in ['A', 'B', 'C', 'D', 'E']
  95.  
  96. return n, r, m
  97. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top