title: How to aggregate results in a collection in Cypher?
body: <p>I am working on a cypher query (Neo4j v2.1.3) where I need to aggregate the results from several collections for use in a separate analysis. I am starting with the following query where I am returning all the Person nodes between the ones we are interested in and a specific Host.</p>
  
  <pre><code>MATCH (person:person), (host:person {name:'Host'}),
  p = shortestPath((person)-[*]-(host))
  WHERE person.name IN ['Steve','Jane']
  RETURN collect(extract(n IN nodes(p)| n.name))
  </code></pre>
  
  <p>This returns a collection that includes the results from both person.name values in my WHERE condition.</p>
  
  <pre><code>Bob, Jordan, John, Jane, Lisa, Robert, John, Bob, John, Lisa, Bob, Lisa
  </code></pre>
  
  <p>What I want is to aggregate the values and list a count of how many each was listed ordered by descending count.</p>
  
  <pre><code>Bob, 3
  John, 3
  Lisa, 3
  Robert, 1
  Jordan, 1
  Jane, 1
  </code></pre>
  
  <p>How can I add to my query to do this in one cypher statement? </p>
  
  <p><strong>UPDATE:</strong> 
  From @Luanne's answer, I had to make an adjustment to get it to work correctly.</p>
  
  <pre><code>MATCH (person:person), (host:person {name:'Host'}),
  p = shortestPath((person)-[*]-(host))
  WHERE person.name IN ['Steve','Jane']
  WITH collect(extract(n IN nodes(p)| n.name)) as nameList 
  UNWIND nameList AS name
  UNWIND name as ind_name
  WITH ind_name, count(*) AS count
  RETURN ind_name,count
  ORDER BY count DESC
  </code></pre>