Sort database data in descending order using a negative timestamp

enter image description here

above is a screenshot of my firebase database. I am trying to sort the bomb data in descending order using a negative timestamp. I use the following command:

  const feedRef = database.ref('ducks')
  feedRef.orderByChild('timestamp').on('value', (snapshot, error) => {
    const feed = snapshot.val()})

I continue to receive the feed in the same order as the database, not in descending order as I want. I think it does not work, because the endpoint of the ducks does not have a temporary child name, how can I achieve this? Do keystrokes generated have timestamp data?

+4
source share
1 answer

.val() , JSON. JavaScript ( ).

Firebase, , JSON, . , DataSnapshot.forEach():

const feedRef = database.ref('ducks')
var feed = [];
feedRef.orderByChild('timestamp').on('value', (snapshot, error) => {
    snapshot.forEach((duckSnap) => {
        const duck = duckSnap.val()
        console.log(duckSnap.key+'='+duck.name);
        feed.push(duck);
    });
});
console.log(feed);
+7

Source: https://habr.com/ru/post/1678819/


All Articles