Firebase群组“包含” queries [英] Firebase complex "contain" queries

查看:128
本文介绍了Firebase群组“包含” queries的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个Android应用程序从rdbms移动到firebase,并且像Firebase中的新手一样,我正在努力处理一些查询。



我在FB中使用DB:

  {
posts:{
-KNnbTHJGm83zpSELWwB:{
\".priority :6gydj46kg0,
branch:分支,
category:Categoria,
过期:24h,
g: 6gydj46kg0,
l:[-23.5415083,-46.88642],
photo:mPostPic_20160728192627.jpeg,
price:10,
priority :0,
product:ipad,
userKey:BNd8RP5qHoc0q7f9gn8cLjPy5Ux1,
offerMessage:Valido吃了14:00 hs,
likeCount:0
}
}
}

in这个职位db我有一个孩子类。我有一个类别的列表,我只需要查询值类别是在这个类别列表里的帖子。



我试过.start()和.end()但不起作用。如果您的条件列表是连续的,您可以使用 startAt () endAt()。既然你说你已经试过了,要么是你做错了什么(看你的代码会在这种情况下允许帮助),要么是标准不是连续的。

后一种情况是更可能,意味着你的愿望是一个相当于SQL的 WHERE类别IN(Categoria,Categorib,Categoric)的查询。 Firebase没有这样的操作。相反,您必须使用 equalTo 来完成多个查询来完成结果。 另外,您可以尝试模拟数据不同以允许一次性检索标准的帖子。这并不总是可能的,但是如果是遵循基于firebase中多个where子句的查询


I am moving an Android app from rdbms to firebase and like a newbie in Firebase I am struggling with some queries.

I have the DB below in FB:

{
  "posts" : {
    "-KNnbTHJGm83zpSELWwB" : {
      ".priority" : "6gydj46kg0",
      "branch" : "Branch",
      "category" : "Categoria",
      "expiration" : "24h",
      "g" : "6gydj46kg0",
      "l" : [ -23.5415083, -46.88642 ],
      "photo" : "mPostPic_20160728192627.jpeg",
      "price" : 10,
      "priority" : 0,
      "product" : "ipad",
      "userKey" : "BNd8RP5qHoc0q7f9gn8cLjPy5Ux1",
      "offerMessage": "Valido ate as 14:00 hs",
      "likeCount": 0
    }
  }
}

in this post db I have a child "category". I have a list of some categories and I need to query only the posts where value category is inside this categories list.

I tried .start() and .end() but is not working.

解决方案

If your list of criteria is consecutive, you can get them with startAt()and endAt(). Since you say you already tried that, either you did something wrong (seeing your code would allow help in that case) or the criteria are not consecutive.

The latter case is more likely and means that your wish is a query equivalent to SQL's WHERE category IN ("Categoria", "Categorib", "Categoric"). Firebase doesn't have such an operation. Instead you'll have to do multiple queries with equalTo to accomplish the result.

Alternatively you can try to model the data differently to allow retrieving the posts for the criteria in one go. This isn't always possible, but if it is it follows the approach outlined in Query based on multiple where clauses in firebase

这篇关于Firebase群组“包含” queries的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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