Firebase 上的通配符查询? [英] Wildcard query on Firebase?

查看:29
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆