1
我正在尝试使用字符串(例如“A”)搜索我的数据库。我只是看着这个火力地堡教程Common SQL Queries converted for the Firebase Database - The Firebase Database For SQL Developers #4并解释说,为了在数据库中搜索字符串(在某个位置),您必须使用:Firebase数据库搜索查询
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") ...
当我去打印从火力地堡快照,我回去。
如果我摆脱了结尾.queryEnding(atValue: "A\\uf8ff")
,数据库将返回Schools
节点中的所有学校。
如何使用字符串搜索Firebase数据库?
Firebase数据库查询区分大小写。在您的示例JSON中,没有以'A'开头的学校名称,只有以'a'(小写)开头的学校名称。 –
您可能知道这一点,但为了清楚起见,该技术将仅搜索字符串*,以字符'A'开头*而不是任何子字符串。 Firebase无法直接搜索子字符串,因此必须使用其他自制方法。 – Jay