gpt4 book ai didi

ios - 如何使用复杂查询从 Firebase 检索数据?

转载 作者:行者123 更新时间:2023-11-29 00:36:41 25 4
gpt4 key购买 nike

我正在尝试为酒店预订创建 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"
}
}
}

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

  1. 舒瓦西什酒店

  2. 柏迪酒店

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

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

最佳答案

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

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

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

像这样为引用酒店的位置创建一个节点,然后您只需读入该节点即可获得酒店列表:

uttara
H3: true
H4: true

或者另一种选择是创建对位置的引用 - 假设 Shuvashish Hotel 在 uttara 和 shonargao 都有位置。深度查询 Hotels 节点的 locations/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

关于ios - 如何使用复杂查询从 Firebase 检索数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40430409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com