Firebase array sorting

Hello, I am using Firebase as as backend.
I have array of songs.
Every song have ‘lastCommentAt’ property, which is the time of the last comment in song (you can comment in every song):

songData.lastCommentAt = Firebase.ServerValue.TIMESTAMP;

Now I want to fetch all of my songs in order of last comments.
Songs feed example:

  • song #341 - last comment in 2 minutes
  • song #2287 - last comment in 51 minutes
  • song #187 - last comment in 3 hours

I already tried ‘.indexOn’ but it’s not helping.

**

The current situation is that the feed is order by create time. I want it to order by lastComment time.

**

Thanks!

Something along the lines of

var query = ref
	.child("songs")
	.orderByChild("lastCommentAt");

I tried it, it’s not working.
I don’t know why it’s not working.
It’s still order by create time…

Dunno… you’re going to have to create a codepen.io or something, also i’d recommend posting this on stackoverflow since it’s not strictly a question on ionic (you won’t find that many people on this forum who know firebase, at least compared to stackoverflow).

Nice one, i’ve replied to the stackoverflow question.

Hey friend thanks for comment. I understood your comment, but I don’t know really know how to fix my code and make it order by ‘lastCommentAt’.
I’ve tried many variations and no one worked corectly…

Sorry mate, can’t really explain it any clearer than on stackoverflow - strongly suggest you read the link i posted in that answer, your problem is the startAt function and not the orderByChild function.