# How to fetch data on from data base having around 60 million node of one type?

**URL:** <https://community.neo4j.com/t/how-to-fetch-data-on-from-data-base-having-around-60-million-node-of-one-type/11122>\
**Category:** Cypher\
**Tags:** performance, cypher\
**Created:** [October 18, 2019, 4:58am UTC](https://community.neo4j.com/t/how-to-fetch-data-on-from-data-base-having-around-60-million-node-of-one-type/11122 "2019-10-18T04:58:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeshveer.yadav](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yeshveer.yadav/32/4634_2.png) [@yeshveer.yadav](https://community.neo4j.com/u/yeshveer.yadav)\
**Post date:** [October 18, 2019, 4:58am UTC](https://community.neo4j.com/t/how-to-fetch-data-on-from-data-base-having-around-60-million-node-of-one-type/11122/1 "2019-10-18T04:58:17Z")

</div>

HI  
i need to run simple match query  
match(n:label)-[:has\_example]-\>(m:label2) with m, count(n.property) as c, collect(n.property) as c2 where c\>100  
return m.property, c,c2 order by c desc limit 10  
on 60+ million nodes ...

 ![plan%20(1)](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/1/1a8a08dadda9a0461d43fac9f4fe9cce0fce274b.png)

and my server is not able to run ,.. how can i make it run via parallel or any other way..??

---

<div class="post-metadata">

**Author:** ![benjamin.squire](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/benjamin.squire/32/1496_2.png) [@benjamin.squire](https://community.neo4j.com/u/benjamin.squire)\
**Post date:** [October 18, 2019, 5:52am UTC](https://community.neo4j.com/t/how-to-fetch-data-on-from-data-base-having-around-60-million-node-of-one-type/11122/2 "2019-10-18T05:52:57Z")

</div>

I am confused on your query, you have  
`collect(n.property) as c, collect(n.property) as c2`  
What is the point of collecting it twice?

As for running in parallel, one method to do this would be using apoc.periodic.iterate. In this case you can't simply return something, you must either set or create. Since you are grouping by m.property what you could do is something like this:  
`CALL apoc.periodic.iterate("MATCH (m:label2) WHERE size((m)<-[:has_example]-()) > 0 RETURN m","WITH m MATCH (m)<-[:has_example]-(n:label) SET m.count_property = count(n.property) , m.count_property2 = count(n.property)",{batchSize:10000,parallel:true,iterateList:true})`  
Then you could run something like  
`MATCH (m:label2) RETURN m.property, m.count_property AS c,m.count_property2 AS c2 ORDER BY c DESC LIMIT 10`  
This can further be sped up with `CREATE INDEX ON :label2(count_property)`

---

<div class="post-metadata">

**Author:** ![yeshveer.yadav](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yeshveer.yadav/32/4634_2.png) [@yeshveer.yadav](https://community.neo4j.com/u/yeshveer.yadav)\
**Post date:** [October 18, 2019, 6:12am UTC](https://community.neo4j.com/t/how-to-fetch-data-on-from-data-base-having-around-60-million-node-of-one-type/11122/3 "2019-10-18T06:12:37Z")

</div>

MATCH (n:user)-[:has\_mobile]-\>(m:Mobile) with m.mobile as Mob\_Number, count(n.ID) as c, collect(n.ID) as id  
where c\>100  
return Mob\_Number,id, c order by c desc limit 10

this is the exact query **one is count and other is collect**

i just need to read data of top ten count

---

<div class="post-metadata">

**Author:** ![benjamin.squire](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/benjamin.squire/32/1496_2.png) [@benjamin.squire](https://community.neo4j.com/u/benjamin.squire)\
**Post date:** [October 18, 2019, 6:28am UTC](https://community.neo4j.com/t/how-to-fetch-data-on-from-data-base-having-around-60-million-node-of-one-type/11122/4 "2019-10-18T06:28:54Z")

</div>

Then it is the same as above only once you get the top ten in the second query you would expand those in order to get the collection of n.ID

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [November 12, 2019, 12:38am UTC](https://community.neo4j.com/t/how-to-fetch-data-on-from-data-base-having-around-60-million-node-of-one-type/11122/5 "2019-11-12T00:38:35Z")

</div>

What does your memory config and disk IO look like?

Can you run PROFILE instead of EXPLAIN?

You could try this:

```auto
match(n:label)-[:has_example]->(m:label2) 
with m, count(*) as c, collect(n) as c2 where c>100
return m.property, c,c2 
order by c desc limit 10

```

Or even better, just do the cheap aggregation + sorting first, then go and re-fetch the related data for the 10 top nodes.

Please take into account that it might blow up the browser if your c is really large, as you would return lists with millions of properties

```auto
match(n:label)-[:has_example]->(m:label2) 
with m, count(*) as c where c>100
with m, c order by c desc limit 10
match (n:label)-[:has_example]->(m) 
with m, c, collect(n.property) as c2 
return m.property, c, c2

```
