Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase -> date order reverse

I am currently making an app using Firebase.

It is one of those bulletin boards that can be seen anywhere on the web.

But there was one problem.

This is a matter of date sorting.

I want to look at the recent date first, but I always see only the data I created first.

postRef.orderByChild('createData').startAt(reverseDate).limitToFirst(1).on('child_added',(data)=>{
    console.log(data.val().name + data.val().createData);
})

result - >hello1496941142093

My firebase treeenter image description here

My code is the same as above.

How can I check my recent posts first?

How Do I order reverse of firebase database?

like image 272
King in the world. Avatar asked Jun 08 '17 18:06

King in the world.


People also ask

How do I reorder documents in firebase?

You can specify the sort order for your data using orderBy() , and you can limit the number of documents retrieved using limit() . Note: An orderBy() clause also filters for existence of the given field.

Can firebase work with Java?

The Firebase Admin SDKs support Firebase access in Java, Python, Node. js, and Go. To get started with a Firebase Admin SDK, see Add the Firebase Admin SDK to Your Server.

How much data can firebase handle?

The total data in each write operation should be less than 256 MB. Multi-path updates are subject to the same size limitation.


1 Answers

The Firebase Database will always return results in ascending order. There is no way to reverse them.

There are two common workaround for this:

  1. Let the database do the filtering, but then reverse the results client-side.
  2. Add an inverted value to the database, and use that for querying.

These options have been covered quite a few times before. So instead of repeating, I'll give a list of previous answers:

  • Display posts in descending posted order
  • Sort firebase data in descending order using negative timestamp
  • firebase sort reverse order
  • Is it possible to reverse a Firebase list?
  • many more from this list: https://www.google.com/search?q=site:stackoverflow.com+firebase+reverse%20sort%20javascript
like image 126
Frank van Puffelen Avatar answered Oct 23 '22 09:10

Frank van Puffelen