问题描述
我正在创建一个Flutter应用程序,该应用程序应查询Firestore集合并在满足两个条件的情况下返回结果.这是我的代码:
I am creating a flutter app that should query a Firestore collection and return results if two conditions are met. Here is my code:
Stream<List<FormQuestions>> get question {
return someCollection
.where('myQUestion', isEqualTo: 'nameQuestion')
.snapshots()
.map(_someQuestionListFromSnapshot);
}
如果我只处理一个.where()条件,它就可以正常工作.但是有两个,尽管我拥有同时满足这两个条件的文档,但没有任何结果.我希望它返回多个.where()条件,如下所示:
If I do with just one .where() condition, it works fine. But with two, it gives no results although I have documents that meet both conditions. I would like it to return for multiple .where() conditions like so:
Stream<List<FormQuestions>> get question {
return someCollection
.where('myQUestion', isEqualTo: 'nameQuestion')
.where('myQuestion', isEqualTo: 'ageQuestion')
.snapshots()
.map(_someQuestionListFromSnapshot);
}
有没有一种方法可以添加OR(||)运算符,或者该如何执行才能获得"nameQuestion"和"ageQuestion"的结果?请协助.谢谢.
Is there a way to add an OR(||) operator or how can I do this so that I get results for both "nameQuestion" and "ageQuestion"? Kindly assist. Thanks.
推荐答案
Firestore不支持常规OR查询,但支持 IN查询,您可以使用它们实现所需的内容.
Firestore does not support regular OR queries, but it does support IN queries with which you can implement what you need.
您的查询看起来像是 citiesRef.where('country','in',['USA','Japan']);
someCollection
.where('myQUestion', whereIn: ['nameQuestion', 'ageQuestion'])
另请参阅:
- Firebase Firestore-OR查询,其答案涵盖了OR的各种变体条件.
-
where
的Flutter参考文档>方法
- Firebase Firestore - OR query, which has answers that cover all kinds of variations of OR conditions.
- the Flutter reference documentation for the
where
method
这篇关于具有OR运算符抖动和Firebase的Compund Query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!