"usersPost": {
"post4543": {
"userID": "X12",
"text": "Hi"
},
"post4544": {
"userID": "X12",
"text": "HELLO"
},
"post454S4": {
"userID": "X143",
"text": "....."
}
}
EqualTo I want to retrieve only posts of some user , let's say "userID": "X12"
EndAt,LimitToLast there is no point to download all snapshot (I have 1M posts), so I limit my downloads to 5 results only.And start from the last saved key
Therefore my code is
OrderByChild("userID").EndAt(lastSavedKey).EqualTo("X12").LimitToLast(5);
//lastSavedKey is the post key "post4544"
That works on Windows, but doesn't work on Android, as I receive:
Error firebase Query::EqualTo: Cannot combine equalTo() with endAt()
I read some posts about issues of combining multiple queries. But what's the alternative solution for my case? Why does it work on Windows? There is no error on Windows! It works perfectly and EndAt the last saved key. (I use Unity Editor)
CodePudding user response:
To implement pagination, you will need to remember two values for the node to start/end at:
- its key
- the value of the property you sort on
If you want to only return nodes with userID
equal to X12
, and end at the one with key lastSavedKey
, you might be able to do that with:
OrderByChild("userID").StartAt("X12").EndAt("X12", lastSavedKey).LimitToLast(5);
I'm saying might here, as I've never tried the combination of startAt, and endAt with a key. If this doesn't work, remove the StartAt
clause - you may just have remove some nodes with a different userID
in your application code in that case.