Firebase数据库 - 如何执行前缀通配符查询 [英] Firebase Database - How to perform a prefix wildcard query
问题描述
我想在Firebase数据库
上执行通配符查询,但不知道这些库是否支持此功能。 - (我想这不是。)
我想要一个最佳的解决方案,在网络流量将尽可能少,假设数据集是数百万条记录 p>
数据集(使用前缀通配符):
user_id:
id_001123:
名称:java
id_002124:
名称:objective-c
id_003125:
名称:swift
代码如何使用通配符检索记录id_002124名称字段,您只有一部分id。例如。 %124。
预期的结果是id_002124,名字是objective-c
任何移动语言示例代码都会很棒。
(Objective-C / Swift / Java)
Firebase数据库查询可以根据对象的键(例如 id_001123
),它们的值(不适用于您的情况)或者子属性的值(例如名称 =
java
)。
具有您指定的特定值,从您指定的值开始的项目或以您指定的值结尾的项目。
所以,您可以创建一个匹配名为< code $> code $ ref $ ref.child(user_id)。 orderByChild(name)。equalTo(objective-c)
或者你可以创建一个查询匹配 id_001124
和 id_001125
与:
ref.child(user_id)。orderByKey()。startAt(id_001125)
或者简单地获取以 id_0011 $开头的所有项目c $ c $:
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ref.child(user_id)。orderByKey()。startAt(id_0011)
或者您可以创建一个匹配 id_001123
和 id_001124
with:
ref.child(user_id)。orderByKey ).endAt(id_001124)
Firebase数据库无法根据值的结尾进行过滤。所以在你当前的数据结构中没有办法得到所有以 4
结尾的项目。
请详细了解Firebase数据库查询: https:// firebase。 google.com/docs/database/android/lists-of-data#sorting_and_filtering_data
查看关于搜索FirebaseL的许多以前的问题p>
- 如何执行sqlLIKE在firebase上运行?
- Firebase查询 - 查找包含字符串的子项 字符串搜索/ 42953600#42953600> Firebaselike搜索字符串
I would like to perform wildcard queries on a Firebase database, and do not know whether the libraries support this. - (my guess it does not.)
I want an optimal solution where the network traffic will be as little as possible, assume the dataset is millions of records.
Dataset (using prefix wildcard):
user_id:
id_001123:
name: "java"
id_002124:
name: "objective-c"
id_003125:
name: "swift"
How would the code look like to retrieve the record id_002124 name field using a wildcard, you only have a portion of the id. eg. "%124".
The expected result would be id_002124, and the name being "objective-c"
Any mobile language example code would great. (Objective-C/Swift/Java)
Firebase Database queries can order/filter data based on the object's keys (e.g. id_001123
), their values (doesn't apply in your case), or the value of a child property (e.g. the fact that name
= "java"
).
For each of these Firebase can match items that have a specific value you specify, items starting at a value you specify, or items ending at a value you specify.
So you can create a query matching the item named objective-c
with:
ref.child("user_id").orderByChild("name").equalTo("objective-c")
Or you can create a query matching id_001124
and id_001125
with:
ref.child("user_id").orderByKey().startAt("id_001125")
Or simply getting all items starting with id_0011
:
ref.child("user_id").orderByKey().startAt("id_0011")
Or you can create a query matching id_001123
and id_001124
with:
ref.child("user_id").orderByKey().endAt("id_001124")
Firebase Database cannot filter based on the end of a value. So there is no way in your current data structure to get all items whose key ends in a 4
.
Please read more about Firebase Database queries here: https://firebase.google.com/docs/database/android/lists-of-data#sorting_and_filtering_data
And see some of the many previous questions about searching for FirebaseL
- How to perform sql "LIKE" operation on firebase?
- Firebase query - Find item with child that contains string
- Firebase "like" search on string
这篇关于Firebase数据库 - 如何执行前缀通配符查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!