2016-06-08 102 views
1

也许我错过了一些东西,但我正在研究用于我的下一个项目的后端。现在,Firebase处于最前沿。Firebase查询在哪里

但是,使用Firebase进行查询时,您似乎无法进行传统的SQL查询,因为它的JSON数据库?如WHOO foo ...似乎只限于EQUALS。

如果我想做一些像WHERE foo小于或者超过,不要告诉我只需要抓取所有数据并在本地过滤它?

或者是因为JSON比SQL数据库轻得多,它只能获取大块的数据分页然后在本地进行过滤更加可行?

我希望你能为我解决这个问题。谢谢。

+0

还有其他一些查询数据的选项 - 您能否提供Firebase结构的一部分(请以文本形式)和用例?用这些数据点直接解决问题会更容易。 – Jay

回答

2

是的,的确,在Firebase中,您不会发现典型的SQL查询,例如简单地执行where something > somevalue,但它们确实提供类似于基本where子句的选项。

例如

如果我们有像where height > 3

查询我们这样做是在像

FQuery *queryRef = [[ref queryOrderedByChild:@"height"] queryStartingAtValue:@3]; 

旧版文档火力解释的很详细 https://www.firebase.com/docs/ios/guide/retrieving-data.html

3

而不是在条款中,有几种方法你可以用它来过滤数据火力...

您检查latest Doc.,部分过滤数据

过滤数据

要过滤数据,你可以混合使用任何的限度或范围的方法在构建查询时使用order-by方法。

Method    | Usage 
------------------------------------------------------------------ 
queryLimitedToFirst  Sets the maximum number of items to return from the beginning of the ordered list of results. 
queryLimitedToLast  Sets the maximum number of items to return from the end of the ordered list of results. 
queryStartingAtValue Return items greater than or equal to the specified key, value, or priority, depending on the order-by method chosen. 
queryEndingAtValue  Return items less than or equal to the specified key, value, or priority, depending on the order-by method chosen. 
queryEqualToValue  Return items equal to the specified key, value, or priority, depending on the order-by method chosen. 

不同于订单的方法,你可以将多个限度或范围功能。例如,您可以组合queryStartingAtValue和queryEndingAtValue方法将结果限制为指定的值范围。