Firebase查询多个where条件 [英] Firebase query for multiple where condition
问题描述
我需要等价查询
从GameScores
中选择玩家名称WHERE Department ='HR'OR Department ='IT'或Department ='Marketing'
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 $ c之间的其他部门的分数$ c>,例如
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 equivalent to sql where in ()
这篇关于Firebase查询多个where条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!