我正在尝试使用字符串(例如“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/