Reputation: 31
I have a question I read from realtime database 1000 last records but I need for example record number 100,200,300... can I do this ? I'm going to make chart and I want for example only show there every 10th measurement. My databse looks like that:
firebase.database().ref("Humidity").ref.orderByChild("time").limitToLast(1000).on("child_added",snapshot => {
Upvotes: 0
Views: 80
Reputation: 598623
It sounds like you're trying to built offset-based pagination, where you first show the most recent 100 messages, then the next 100, etc. That is not how pagination in Firebase works.
Pagination on Firebase follows a cursor model, and is based on knowing an anchor node. For example, if you've first shown the 100 most recent messages, you know the timestamp and key of the oldest message you've shown. You can then get the 100 messages before that with:
firebase.database().ref("Humidity")
.orderByChild("time")
.endAt(oldestTimeValue, oldestKey) // 👈 new
.limitToLast(100)
.on("child_added",snapshot => {
This:
time
value.time
is oldestTimeValue
and whose key (typically a push key like -M...
) is oldestKey
(just in case there are multiple nodes with the same time
value).Upvotes: 1