鉴于以下数据结构:
{ "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/" } } }
我想检索给定链接的所有注释,并按相反的时间顺序对它们进行排序.我已经做到了这一点,但我无法弄清楚如何进行反向排序,因为我已经使用orderByChild通过链接缩小结果范围:
ref.orderByChild('link').equalTo(currentLink).on('value', function (snap) { console.log(snapshot.val()); });
如果我第二次这样调用orderByChild():
ref.orderByChild('link').equalTo(currentLink).orderByChild('createdAt').on('value', function (snap) { console.log(snapshot.val()); });
它失败并显示以下错误消息:
未捕获的错误:Query.orderByChild:您无法组合多个orderBy调用.
我很难过.有什么建议?