How to get data from a Firebase database in descending order?

I was wondering if the new firebase database added this feature because I need it in my project.

The structure looks like this.

enter image description here

and ya setting up RecyclerView for reverse work for me, because it makes it start from the bottom.

Decision

So this is the best solution I can think of. Now.

As @Frank said, this may be a duplicate, but I solved it first with it.

So what we can do is do timeStamp negative ie -20164846476589

and then Subtracting it with some higher value, for example 999999999999999L (which so far will not exceed offcourse), and then what we get. It would be the lowest downstream value for the new timestamp.

and the data will automatically disappear in Firebase

t

String NewDescTimeStamp= String.valueOf((9999999999999L+(-1 * PreviousTimestamp))); mFirebaseRef.child(NewDescTimeStamp).setValue(true); 
+7
java android firebase firebase-database
source share
1 answer

You cannot do this using the existing API.

You can use one or more of the following methods to retrieve a known number of children: limitToFirst() , limitToLast() , startAt() , endAt()

You can also use one of the ordering methods: orderByChild() , orderByValue() , orderByKey()

Than, Save them in a data structure (e.g. ArrayList ), and then use java.util.Collections.reverse() to cancel the list.

With firebase, you must make part of the client request logic. Not all operations available in SQL are available in Firebase.

+13
source share

All Articles