Given the following data structure:
{ "comments" : { "-JcBbk64Gpm1SKoFHv8b" : { "content" : "blah", "createdAt" : 1417550954985, "link" : "http%3A%2F%2Flocalhost%3A3000%2F", "recommendedCount" : 0, "replies" : { "-JcBbk8gF_nQ_vjwag61" : true }, "replyCount" : 1 }, "-JcBbk8gF_nQ_vjwag61" : { "content" : "blah blah", "createdAt" : 1417550955151, "link" : "http%3A%2F%2Flocalhost%3A3000%2F", "recommendedCount" : 0, "replyCount" : 1, "replyToComment" : "-JcBbk64Gpm1SKoFHv8b" } }, "links" : { "http%3A%2F%2Flocalhost%3A3000%2F" : { "author" : 5, "commentCount" : 2, "comments" : { "-JcBbk64Gpm1SKoFHv8b" : true, "-JcBbk8gF_nQ_vjwag61" : true }, "createdAt" : 1417550954931, "ratingCount" : 2, "recommendedCount" : 32, "score" : 91, "title" : "A Christian vs. an Atheist: Round 2", "url" : "http://localhost:3000/" } } }
I would like to get all the comments for this link and sort them in reverse chronological order. I got this far, but I canβt figure out how to do reverse sorting, because I already used orderByChild to narrow down the results by reference:
ref.orderByChild('link').equalTo(currentLink).on('value', function (snap) { console.log(snapshot.val()); });
If I call orderByChild () a second time, like this:
ref.orderByChild('link').equalTo(currentLink).orderByChild('createdAt').on('value', function (snap) { console.log(snapshot.val()); });
with this error message fails:
Unprepared error: Query.orderByChild: you cannot combine multiple orderBy calls.
I'm at a dead end. Any suggestions?