Sort from the most recent to the oldest in firebase

0

Currently I am able to sort the posts by date, but since they have been saved by timestamp, it is always displayed from the oldest to the newest, I would like to do the reverse, with the newest publications first. Here is my current code:

        database.ref("Pedidos").orderByChild("data_pedido").on('child_added', function(snapshot){

How the date is being saved in the bank:

Thank you for your attention.

    
asked by anonymous 06.09.2017 / 21:42

1 answer

0

As explained in this topic the firebase can sort from increasing form with the use of the function limitToFirst (n first items) or limitToLast (n last items).

To be able to search in descending order, there are two other options:

  • Reorder the data internally in your application.
  • Create a new field and store a timestamp in descending order, for example:

    -1 * new Date (). getTime ();

11.09.2017 / 19:52