Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-17-2019 11:23 PM
Is it possible to get total and paging data in one query? Say I have 100 total rows and my output looks like
{
"total": 100,
"list": [1, 3, 5, 7, 10]
}
I tried to achieve this with a query like
MATCH (:User {uid: $uid})-[:R1]->(:Chat)<-[:R2]-(:Post)<-[:R3]-(u:User)
WHERE NOT EXISTS(u.someproperty)
WITH u.uid as uids, count(u) as total
skip 0 limit 5
RETURN {list: collect(uids), total: total}
OR
MATCH (:User {uid: $uid})-[:R1]->(:Chat)<-[:R2]-(:Post)<-[:R3]-(u:User)
WHERE NOT EXISTS(u.someproperty)
WITH count(u) as total, u
WITH u.uid as uids, total
skip 0 limit 5
RETURN {list: collect(uids), total: total}
but the result looks like this
{
"total": 2,
"list": [
1
]
}
{
"total": 3,
"list": [
4,
3,
6,
7
]
}
Solved! Go to Solution.
09-17-2019 11:56 PM
I found this post from Stackoverflow that helps.
For my problem, it can be solved by splitting the Match clause.
MATCH (:User {uid: $uid})-[:R1]->(:Chat)<-[:R2]-(:Post)<-[:R3]-(u:User)
WHERE NOT EXISTS(u.someproperty)
WITH count(u) as total
MATCH (:User {uid: $uid})-[:R1]->(:Chat)<-[:R2]-(:Post)<-[:R3]-(u:User)
WHERE NOT EXISTS(u.someproperty)
WITH u.uid as uids, total
skip 0 limit 5
RETURN {list: collect(uids), total: total}
But I am not sure about the performance, is it better to execute two queries or is it better like the solution above.
09-17-2019 11:56 PM
I found this post from Stackoverflow that helps.
For my problem, it can be solved by splitting the Match clause.
MATCH (:User {uid: $uid})-[:R1]->(:Chat)<-[:R2]-(:Post)<-[:R3]-(u:User)
WHERE NOT EXISTS(u.someproperty)
WITH count(u) as total
MATCH (:User {uid: $uid})-[:R1]->(:Chat)<-[:R2]-(:Post)<-[:R3]-(u:User)
WHERE NOT EXISTS(u.someproperty)
WITH u.uid as uids, total
skip 0 limit 5
RETURN {list: collect(uids), total: total}
But I am not sure about the performance, is it better to execute two queries or is it better like the solution above.
All the sessions of the conference are now available online