Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase limitToLast Query

My question maybe a silly one, I´ve read the documentation but haven´t got a solution to my question. When I use limitToLast to get the last 15 messages (lets say from 5-20) and if I delete the 20th message, the childListener returns me messages like this (5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-4)... As you can see the last item is number 4. The code is like so:
messagesListener = FBMessagesRef.limitToLast(15).addChildEventListener(new ChildEventListener(), how can I fix it and dont get the 4th item

like image 544
Andrey Avatar asked Sep 30 '16 16:09

Andrey


People also ask

What is limitToLast method in Firebase?

The limitToLast() method is used to set a maximum number of children to be synced for a given callback. If we set a limit of 100, we will initially only receive up to 100 child_added events. If we have less than 100 messages stored in our database, a child_added event will fire for each message.

Can you query from Firebase?

Querying DataWith Firebase database queries, you can selectively retrieve data based on various factors. To construct a query in your database, you start by specifying how you want your data to be ordered using one of the ordering functions: orderByChild() , orderByKey() , or orderByValue() .

How do I get particular data from Firebase?

Firebase data is retrieved by either a one time call to GetValueAsync() or attaching to an event on a FirebaseDatabase reference. The event listener is called once for the initial state of the data and again anytime the data changes.


1 Answers

Since you're getting the last 15 digits when you set the value to 15, change the limitToLast value to -1 to get the last Firebase value. Change your code to below snippet.

messagesListener = FBMessagesRef.limitToLast(-1).addChildEventListener(new ChildEventListener(),
like image 123
devmike01 Avatar answered Oct 20 '22 20:10

devmike01