Firebase 查询多个 where 条件 [英] Firebase query for multiple where condition
问题描述
我需要
从 GameScores 中选择玩家姓名WHERE 部门 = 'HR' OR 部门 = 'IT' OR 部门 = '营销'
SELECT PlayerName FROM GameScores WHERE Department = 'HR' OR Department = 'IT' OR Department = 'Marketing'
在 Firebase for android 中,我不想要多次调用,只需要一次请求并获取与 where 子句键匹配的所有数据.我该怎么做?
In Firebase for android , I don't want multiple call, just one request and get all data that match with where clause key. How I can do it?
推荐答案
在 Firebase 中过滤多个值的属性的唯一方法是这些值是否在一个范围内.例如,您可以获得与您的值匹配的所有项目:
The only way to filter a property on multiple values in Firebase is if those values are in a range. For example, you could get all items matching your values with:
ref.child("GameScores")
.orderByChild("Department")
.startAt("HR")
.endAt("Marketing")
这样做的问题是它还会匹配其他部门名称在HR
和Marketing
之间的分数,例如
The problem with this is that it also matches scores from other departments whose name is between HR
and Marketing
, such as
Firebase 实时数据库或 Cloud Firestore 无法将多个单独的值传递到查询中.您必须为每个值执行单独的查询并在客户端合并它们.
There is no way in either the Firebase Realtime Database or Cloud Firestore to pass multiple separate values into a query. You will have to execute a separate query for each value and merge them client-side.
另见:
这篇关于Firebase 查询多个 where 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!