Firebase 上的通配符查询? [英] Wildcard query on Firebase?
问题描述
是否可以在 Firebase 上进行通配符查询?例如:
Is it possible to do wildcard queries on Firebase? For example:
https://foo.firebaseio.com/person.json?orderBy="name"&equalTo="Lun*"
推荐答案
我知道已经有一段时间了,但我认为其他人可能会感兴趣.您可以伪造"通配符搜索,例如 foo*
(因此基本上您可以搜索以指定字符串开头的值).
I know it's been a while but I thought that others might be interested. You can "fake" a wildcard search for things like foo*
(so basically you can search for values beginning with a specified string).
对于 iOS 和Swift 它看起来像这样:
For iOS & Swift it would look like this:
dbReference.child("person").queryOrdered(byChild: "name").queryStarting(atValue: "foo").queryEnding(atValue: "foou{f8ff}").observe(.childAdded) { (snapshot: FIRDataSnapshot) in
print("(snapshot.key) - (String(describing: snapshot.value))")
}
这样做是使用 name
属性的开始和结束值,其中结束键等于开始 + Unicode 范围内的一个非常高的代码点.因为它在 Unicode 中大多数常规字符之后,所以查询匹配所有以 foo
开头的值.
What this does is using a start and end values for name
property where the end key is equal to the start + a very high code point in the Unicode range. Because it is after most regular characters in Unicode, the query matches all values that start with foo
.
这篇关于Firebase 上的通配符查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!