Yoann Maingon
Yoann Maingon

Reputation: 315

Can you get the full count of result even when using limit clause with Neo4j

I'm limiting the number of results for performance reason, so I have a query like

MATCH (a:Part) RETURN a limit 50

Is it possible to get the full count of node with label Part in order to display that the result represents 50 results out of X total records?

Upvotes: 1

Views: 1025

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

But it will be more expensive and not that efficient as it has to load/pull all data.

You can either do (prob more efficient):

MATCH (a:Part) 
WITH count(*) as c
MATCH (a:Part)
RETURN c,a 
limit 50

or

MATCH (a:Part) 
WITH count(*) as c,collect(a)[0..50] as parts
UNWIND parts as a
RETURN c,a 
limit 50

Upvotes: 7

Related Questions