Firebase startAt String仅采用第一个字符

编程入门 行业动态 更新时间:2024-10-19 13:22:15
本文介绍了Firebase startAt String仅采用第一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在xyz下具有如下结构

I have a structure like below under xyz

{ "pushKey000": { "findKey": "john_1", "userName": "john", "topic": 1 }, "pushKey001": { "findKey": "john_2", "userName": "john", "topic": 2 }, "pushKey002": { "findKey": "joel_1", "userName": "joel", "topic": 1 } }

现在正在尝试查询,我要查找所有以" john "开头的findKey的条目的数据.我尝试了以下操作:(例如,使用REST)

Now am trying to make a query where I want data of all entries with findKey starting with "john". I tried the following:(Using REST for example)

abc.firebaseio/xyz.json?orderBy=abc.firebaseio/xyz.json?orderBy="findKey"&startAt="john"

这给了我所有的结果,包括"joel".基本上,它只使用 startAt 的第一个字符,在本例中为 J .

This gives me all the results including 'joel'. Basically it just uses the first character of startAt, in this case J.

此 firebase视频触发相同类型的查询,但仅使用第一个字符进行搜索.

This firebase video fires the same type of query but only searches with just first character.

我在做错什么吗,还是有其他方法可以使用findKey检索它?非常感谢您的提前帮助

Is there something wrong that I am doing or is there is any other way to retrieve it using findKey? Thanks a lot for the help in advance

PS:我的.indexOn位于findKey上,无法更改

PS: My .indexOn is on findKey and can't change it

推荐答案

您的代码没有任何问题,您的期望也有问题.(我一直想把它写成答案:))

There is nothing wrong with your code, there is something wrong with your expectations. (I always wanted to write that as an answer :))

startAt()函数用作查询的起点,而不是过滤器.因此,在您的情况下,它将找到约翰"的第一个出现,并从该点开始返回所有内容(包括乔尔,凯文,蒂姆等).

The startAt() function works as a starting point for your query, not a filter. So in your case it will find the first occurance of "john" and return everything from that point forward (Including Joel, Kevin, Tim, etc...).

不幸的是,没有直接方法可以进行查询,其中findKey包含字符串"john" .但幸运的是,有一种使用 endAt()的(部分)解决方法.

Unfortunatly there is no direct way to do a query where findKey contains the string "john". But luckely there is a (partial) workaround using endAt().

您的查询将如下所示:

orderBy="findKey"&startAt="john"&endAt="john\uf8ff"

此处 \ uf8ff 是最后一个unicode字符(如果我输入错了,请纠正我).

Here \uf8ff is the last unicode character (please correct me if I'm wrong).

使用此命令,您可以查询以"john"开头的值,例如"johnnie","johnn","john".但不是"1john","johm"或"joel".

With this you can query for values that start with "john" like "johnnie", "johnn", "john". But not "1john" or "johm" or "joel".

更多推荐

Firebase startAt String仅采用第一个字符

本文发布于:2023-11-13 00:38:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582928.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   字符   Firebase   startAt   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!