Firebase limitToLast Query

My question may be stupid, I read the documentation, but I did not have a solution to my question. When I use limitToLast to receive the last 15 messages (say 5 to 20), and if I delete the 20th message, childListener will return me such messages (5-6-7-8-9-10-11-12- 13-14-15-16-17-18-19-4) ... As you can see, the last element is number 4. The code looks like this:
messagesListener = FBMessagesRef.limitToLast(15).addChildEventListener(new ChildEventListener()how can I fix it and not get the 4th element

+4
source share
2 answers

Since you get the last 15 digits when you set the value to 15, change the value limitToLastto -1to get the latest Firebase value. Change the code below.

messagesListener = FBMessagesRef.limitToLast(-1).addChildEventListener(new ChildEventListener(),
0
source

The official Firebase documentation says that if the limit value is less than the number of items in the database, then it will read all the items in the database. It is clear what I think.

limitToLast (limit) returns firebase.database.Query

Creates a new query object limited to the last specific number of children.

limitToLast() . 100, 100 . , 100 , , child_added . , 100 , child_added 100 . , child_removed , , 100.

0

Source: https://habr.com/ru/post/1656396/


All Articles