在Firebase查询中组合orderByChild和equalTo

 夜夜0603 发布于 2022-12-07 11:43

鉴于以下数据结构:

{
  "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调用.

我很难过.有什么建议?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有