json - Firebase 数据库搜索查询

标签 json swift firebase firebase-realtime-database

我正在尝试使用字符串(例如“A”)搜索我的数据库。我只是在看这个 Firebase 教程 Common SQL Queries converted for the Firebase Database - The Firebase Database For SQL Developers #4它解释说,为了在数据库中搜索字符串(在特定位置),您必须使用:

firebase.database().ref.child("child_name_here")
    .queryOrdered(byChild: "child_name_here")
    .queryStarting(atValue: "value_here_uppercase")
    .queryEnding(atValue: "value_here_uppercase\\uf8ff")

必须在结束值中使用两个\\作为转义符才能得到一个\

当我尝试使用我的 Firebase 数据库时,它不起作用。这是我的数据库:

{
    "Schools": {
        "randomUID": {
            "location" : "anyTown, anyState",
            "name" : "anyName"
        }
    }
}

这是我的查询:

databaseReference.child("Schools")
    .queryOrdered(byChild: "name")
    .queryStarting(atValue: "A")
    .queryEnding(atValue: "A\\uf8ff") ...

当我从 Firebase 打印快照时,我回来了。

如果我去掉结尾的 .queryEnding(atValue: "A\\uf8ff"),数据库将返回 Schools 节点中的所有学校。

如何使用字符串搜索 Firebase 数据库?

最佳答案

queryStarting()queryEnding() 可用于数字。例如:您可以获得 someField 从 3 到 10 不等的对象。

用于搜索字符串:您可以使用 queryEqualToValue() 搜索整个字符串。

关于json - Firebase 数据库搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41070244/

相关文章:

ios - JSON 日期到 NSDate 结果为零

javascript - 带有 JSON 数据的 DataTable

javascript - 大型 JSON 字符串未使用 JSON.parse 或 angular.fromJson 进行解析

swift - Swift + Combine 中是否有类似于 PromiseKit 的 "ensure"的功能?

javascript - 数组包含未获取二维数组中的结果

c# - 如何在 Mono 中反序列化 JSON 字符串?

ios - 在表格 View 中使用两个不同的单元格

ios - 关键帧动画在移动帧时出现模糊?

ios - 从存储中下载图像时出现可选错误,我已将字符串转换为 URL

firebase - 如何在 firebase phone-auth (OTP) android 中禁用 reCaptcha?