Firestore: orderBy in desc order returns empty array if combined with startAfter #4601
Answered
by
Hamza-Khurshid
Hamza-Khurshid
asked this question in
Q&A
Replies: 2 comments
-
This should be an issue, not a discussion. Please open a new issue following the template |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey Mike
It was my mistake I just stepped on the solution.
I thought startAfter receives the starting index of query but it was actually field value.
`db.collection("users") .orderBy(votes', 'desc') .startAfter(page*5) .limit(5) .get()`
here I was keeping page numbers and then multiplying with 5 to get next five results.
But now I give the number of votes of last user in startAfter so that next users can be fetched:
`db.collection("users") .orderBy(votes', 'desc') .startAfter(1020) .limit(5) .get()`
…On Tue, Nov 24, 2020 at 12:07 AM Mike Hardy ***@***.***> wrote:
This should be an issue, not a discussion. Please open a new issue
following the template
Prior to doing that though, please make sure this works in general
(perhaps by doing a quick test with firebase-js-sdk or by checking how we
validate it in our test suite - do we exercise this functionality? If not
and you add a test does it fail?
https://github.com/invertase/react-native-firebase/tree/master/packages/firestore/e2e/Query
)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4601 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALKNU7V5L5EEAJJBDGIBVX3SRKXG5ANCNFSM4T7Z2KDQ>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Hamza-Khurshid
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Issue
I am trying to query a list of users in firestore that should be sorted in descending order by number of "votes" property and using startAfter to paginate the results.
But it returns empty array always. It returns results if I change orderBy to asc. I have followed documentation but still facing this unexpected behavior.
db.collection("users") .orderBy(votes', 'desc') .startAfter(page*5) .limit(5) .get()
Project Files
Dependencies
Click To Expand
package.json
:"dependencies": {
"@react-native-firebase/app": "^10.0.0",
"@react-native-firebase/auth": "^10.0.0",
"@react-native-firebase/firestore": "^10.0.0",
"@react-native-firebase/storage": "^10.0.0",
"@react-navigation/bottom-tabs": "^5.8.0",
"@react-navigation/native": "^5.7.3",
"@react-navigation/stack": "^5.9.0",
"axios": "^0.21.0",
"firebase": "^7.21.0",
"native-base": "^2.13.14",
"prop-types": "^15.7.2",
"react": "16.13.1",
"react-native": "0.63.2",
# N/A
Beta Was this translation helpful? Give feedback.
All reactions