【问题标题】:How to do the following query in Firebase? (more than one where condition) [duplicate]如何在 Firebase 中进行以下查询? (多个where条件)[重复]
【发布时间】:2015-02-10 11:29:21
【问题描述】:

考虑以下 Firebase 结构:

{
  "users" : {
    "00:03:aa:dc:1c:2b" : {
      "firstName" : " Ofek",
      "groupName" : "thailand",
      "lastName" : "Ron",
      "registration" : {
        "type" : "regular",
        "time" : 1418288589636
      },
      "phoneNumber" : "345345345"
    },
    "04:46:65:8D:60:C6" : {
      "firstName" : " Ofek",
      "groupName" : "thailand",
      "lastName" : "Ron",
       "registration" : {
        "type" : "regular",
        "time" : 1418288589630
      },
      "phoneNumber" : "345345345"
    },
  }
}

你如何实现以下查询:

SELECT * FROM USERS WHERE groupName="thailand" and registration.time>=1418288589631

我试图这样做:

fireBase.orderByChild("groupName").startAt("thailand").endAt("thailand").orderByChild("time").startAt("1418288589631")

但这引发了异常,因为 firebase 不允许多个 orderbys...

有什么想法吗?

【问题讨论】:

  • Firebase 目前仅支持每个查询使用一个 orderBy。因此,如果您想过滤更多属性,则必须在 JavaScript 代码中执行额外的过滤客户端,或者您必须提出自己的索引方案来组合属性。
  • 这应该是弗兰克的答案!

标签: android firebase


【解决方案1】:

Firebase 目前仅支持每个查询使用一个 orderBy

因此,如果您想对多个属性进行过滤(或排序),您要么必须在 JavaScript 代码中进行额外的客户端过滤(或排序),要么您必须提出您的结合属性的自己的索引方案。

【讨论】:

    猜你喜欢
    • 2018-05-06
    • 2021-11-05
    • 1970-01-01
    • 2022-01-01
    • 2016-10-23
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多