Firebase数据库搜索查询 [英] Firebase Database Search Query
问题描述
我正在尝试使用字符串(例如"A")搜索数据库.我只是在看此Firebase教程已为Firebase数据库转换的通用SQL查询-Firebase对于SQL Developers#4的数据库,它解释说,为了在数据库中搜索字符串(在特定位置),必须使用:
I am trying to search my database using a string, such as "A". I was just watching this Firebase tutorial Common SQL Queries converted for the Firebase Database - The Firebase Database For SQL Developers #4 and it explains that, in order to search the database for a string (in a certain location), you must use:
firebase.database().ref.child("child_name_here")
.queryOrdered(byChild: "child_name_here")
.queryStarting(atValue: "value_here_uppercase")
.queryEnding(atValue: "value_here_uppercase\\uf8ff")
为了获得一个\
,必须在结束值中使用两个\\
作为转义字符.
You must use two \\
in the ending value as an escape character in order to get one \
.
当我在Firebase数据库中尝试此操作时,它不起作用.这是我的数据库:
When I try this with my Firebase database, it does not work. Here is my database:
{
"Schools": {
"randomUID": {
"location" : "anyTown, anyState",
"name" : "anyName"
}
}
}
这是我的查询:
databaseReference.child("Schools")
.queryOrdered(byChild: "name")
.queryStarting(atValue: "A")
.queryEnding(atValue: "A\\uf8ff") ...
当我从Firebase打印快照时,我回来了.
When I go to print the snapshot from Firebase, I get back.
如果我删除了结尾.queryEnding(atValue: "A\\uf8ff")
,则数据库将返回Schools
节点中的所有学校.
If I get rid of the ending .queryEnding(atValue: "A\\uf8ff")
, the database returns all of the schools in the Schools
node.
如何使用字符串搜索Firebase数据库?
推荐答案
这将显示与Wick
匹配的所有客户. (不是很快,但可能会给您一个想法)
This shows all customers that match Wick
. (It's not swift but may give you an idea)
// sample
let query = 'Wick'
clientsRef.orderByChild('name')
.startAt(query)
.endAt(query + '\uf8ff')
.once('value', (snapshot) => {
....
})
这篇关于Firebase数据库搜索查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!