0
votes

I have a simple graph in Neo4j graph-database:

simple graph

How to find nodes (using cypher) which:

  1. have 3 relationships (result: node c, node e)?
  2. have 2 outgoing relationships (result: node c, node e)?
  3. have 1 incoming and 1 outgoing relationships only (result: node a, node b, node d, node d1)?
1
I have no idea unfortunately. Can you suggest me a direction for thinking? For example more examples of complex and very complex queries?Alexey Egorov

1 Answers

4
votes

This will get you started, but you should really read the manual, it's very detailed and easy to follow- http://neo4j.com/docs/stable/cypher-query-lang.html

Also consider the online course- http://neo4j.com/graphacademy/online-course-getting-started/

  1. Nodes that have 3 relationships:

    MATCH (n) WHERE size((n)--())=3 RETURN n

  2. Nodes that have 2 outgoing relationships:

    MATCH (n) WHERE size((n)-->())=2 RETURN n

  3. Nodes that have one outgoing and one incoming relationship

    MATCH (n) WHERE size((n)-->())=1 AND size((n)<--())=1 RETURN n

You should use labels btw.