Skip to content
Advertisement

How to get all the firebase data up to second from last

In my firebase, the recently or last added data has to be ubsent all the time from my table. So I want to populate the table with all the data except for the recently added data. I mean to say I have data1, data2, data3, data4. I want only data1 to 3, and 4 should be ignored. I thought I could use something like limitToFirst(-1) could work, unfortunately it doesnt.

this is my line of code: var database = firebase.database().ref().child('Sales/JBC');

I tried: var database = firebase.database().ref().child('Sales/JBC').limitToFirst(-1);

Advertisement

Answer

Assuming you are certain that the data/node/key that you do not want to retrieve is always at the bottom., the trick you would need to use is, first know how man data you have, there are so many ways of getting count of data. Once you have the count you can use limitToFirst() method. So you say: if you want to ignore the last child, go like this: limitToFirst(count-1). This means if you have 20 elements, you need the first 19, so get count of elements (thus 20) then subtract 1. If you want up to 18 elements you subtract 2. And so on…

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement