How To Retrieve Firebase Database Start From Bottom To Up?
I have a set of items in firebase realtime, when i Retrieve data the old data appears at the first. Already i tried Firebase.database().ref().child('chains').orderByKey().start
Solution 1:
How do you determine which items is newer? Is there any child node containing timestamp? If yes then you should use orderByChild()
:
firebase.database().ref('chains').orderByChild('addedAt')
However this will sort by ascending order and hence oldest items will be retrieved first. If you are looking for latest 50 items then you can use limitToLast
method and then reverse the order using Javascript:
firebase.database().ref('chains').orderByChild('addedAt').limitToLast(50)
If you are ordering them using the item keys then you can use orderByKey
but to get items in descending order i.e. newest first, you'll have to use same logic with limitToLast.
Post a Comment for "How To Retrieve Firebase Database Start From Bottom To Up?"