我见过之前针对早期版本的 Firebase 提出过这个问题 https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase这不再适用于 Firebase Cloud Firestore。
我想进行一个查询,根据潜在值列表检查文档字段的值,例如whereEqualTo(someField, a OR b OR c OR ... OR n)
。具体来说,我有一个引用类型的单个字段的潜在值列表,并且我希望我的查询返回指定集合中的所有文档,其字段值等于列表中的潜在值之一。我也在使用.limit(10)
因为我正在对数据进行分页。
例如,如果我的列表包含引用 [ref1, ref2, ref3],那么查询将类似于连接这 3 个查询:
查询 query1 = mDatabase.collection("myCollection").whereEqualTo("refField", ref1);
查询 query2 = mDatabase.collection("myCollection").whereEqualTo("refField", ref2);
查询 query3 = mDatabase.collection("myCollection").whereEqualTo("refField", ref3);
On the 文档 https://firebase.google.com/docs/firestore/query-data/queries,在“限制”部分下,它提到:
Logical OR queries. In this case, you should create a separate query for each OR condition and merge the query results in your app.
因此,也许最好的方法是合并查询结果,但是如何才能做到这一点,并且限制为 10 个结果呢?
请注意,我正在使用 Java 进行 Android 开发。