【问题标题】:How can I use a complex query to retrieve data from Firebase?如何使用复杂查询从 Firebase 检索数据?
【发布时间】:2017-03-18 17:51:34
【问题描述】:

我正在尝试为酒店预订创建 ios 应用程序。我所有的数据都存储在 Firebase 中。我的酒店名称和位置存储在“HotelLocation”表中。

{
"HotelLocation": {
    "H1": {
        "name": "Ghetu hotel",
        "location": "shonargao,dhaka"
    },
    "H2": {
        "name": "BB hotel",
        "location": "gulshan,dhaka"
    },
    "H3": {
        "name": "Shuvashish hotel",
        "location": "uttara,dhaka"
    },
    "H4": {
        "name": "Bodi hotel",
        "location": "uttara,dhaka"
    }
  }  
 }

这是我的 json 格式的表“HotelLocation”,但我无法从该表中仅检索“uttara”的数据,即如果我搜索 uttara,那么我应该得到 ​​p>

  1. 舒瓦什酒店

  2. 博迪酒店

我尝试使用“queryEqualToValue”,但问题是“uttara,dhaka”,因为 firebase 区分大小写。所以“,dhaka”正在制造问题。

有没有办法在 Firebase 中使用 SQL 命令“%LIKE%”?

【问题讨论】:

标签: ios firebase swift2 firebase-realtime-database


【解决方案1】:

如果您使用 queryStartingAt("uttara") 和 queryEndingAt("uttara"),它将返回您想要的节点。

您无法对通配符进行精确搜索。

还有很多其他方法可以解决这个问题...

为引用此类酒店的位置创建一个节点,然后您可以在该节点中读取并获得酒店列表:

uttara
   H3: true
   H4: true

或者另一种选择是创建对位置的引用 - 假设 Shuvashish Hotel 在 uttara 和 shonargao 都有位置。深入查询 Hotels 节点的位置/L1 = true 将返回 H3

locations
   L1: "uttara"
   L2: "gulshan"
   L3: "shonargao"


Hotels
     H2
       "name:": "BB hotel"
       "locations"
          L2: true
    H3
       "name": "Shuvashish hotel",
       "locations"
          L1: true
          L3: true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多