I\'m trying to test out Firebase to allow users to post comments using push
. I want to display the data I retrieve with the following;
fbl.child
To add to Dave Vávra's answer, I use a negative timestamp as my sort_key
like so
Setting
const timestamp = new Date().getTime();
const data = {
name: 'John Doe',
city: 'New York',
sort_key: timestamp * -1 // Gets the negative value of the timestamp
}
Getting
const ref = firebase.database().ref('business-images').child(id);
const query = ref.orderByChild('sort_key');
return $firebaseArray(query); // AngularFire function
This fetches all objects from newest to oldest. You can also $indexOn
the sortKey
to make it run even faster