问题描述
我上面有JSON结构
I have the JSON structure above
我想获取其ID以"123"结尾的车辆列表
I want to get the list of vehicles where their ids ends with "123"
我曾经尝试使用Query.endAt()方法,但是我不确定我是在正确使用它还是不应该提供所需的输出
I had tried to use Query.endAt() method but i'm not sure if i'm using it right or it shouldn't give the required output
Query vehiclesRef;
vehiclesRef = db.getReference("vehicles").orderByKey().endAt("\uf8ff123");
推荐答案
Firebase数据库查询只能执行前缀匹配,因此字符串以特定字符串开头或以字符串范围开头.无法查询具有特定值的字符串 ending 或以某个值范围结尾的字符串.
Firebase Database queries can only perform prefix matches, so strings starting with a specific string or starting with a range of string. It is not possible to query for strings ending with a specific value, nor those ending with a range of values.
如果您真的想在Firebase中执行此操作,请考虑将反向字符串也存储在数据库中:
If you really want to do this within Firebase, consider also storing the reversed strings in the database:
"321_1_0"
"321_3_0"
"654_52_0"
然后您可以使用
321查询以 321
开头的字符串
Then you can query for strings starting with 321
with
vehiclesQuery = db.getReference("vehicles").orderByKey().startAt("321").endAt("321\uf8ff");
这篇关于Firebase匹配子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!