title: find paths with specific length combined with nodes with specific degree neo4j
body: <p>I am trying to write a query to find all nodes with outdegree X and only return the paths that contains those nodes when path length is equal to Y </p>
  
  <p>If I want to get only nodes with outdegree X I use the following Cypher query </p>
  
  <pre><code>MATCH (s:URL)-[r:VISITED*]-&gt;(t:URL) 
  WITH s, count(t) as degreeout 
  WHERE 73 in s.job_id and degreeout &lt;4 
  return s, degreeout
  </code></pre>
  
  <p>If I want to get only paths with length = X I use the following query </p>
  
  <pre><code>MATCH p=(s:URL)-[r:VISITED*]-&gt;(t:URL)
  WHERE length(p)=7
  return p 
  </code></pre>
  
  <p>I tried the combine the previous two queries in the following query </p>
  
  <pre><code>MATCH (s:URL)-[r:VISITED*]-&gt;(t:URL)
  WITH s, COLLECT(DISTINCT id(s)) as matched, count(t) as degreeout
  WHERE 73 in s.job_id and degreeout &lt;4
  MATCH p=(s2:URL)-[r:VISITED*]-(t2:URL)
  WHERE id(s2) in matched and length(p) &gt;=1
  RETURN p
  </code></pre>
  
  <p>Whenever I execute the query, the machine keeps processing and then I get an error no enough memory.</p>
  
  <p>It seems like there is an infinite loop !!</p>