问题
I would like to ask if there is a document in the collection with the field "test" equal to 1 2 or 4. But unfortunately I have not found a suitable solution.
This is my approach Unfortunately, this does not work here (is Equal To 1 | 2 | 4). Is that no or operator? (|)
Future getPostsToday() async {
...
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection("Data").where("test", isEqualTo: 1 | 2 | 4 ).getDocuments();
return qn.documents;
}
回答1:
Cloud Firestore does not support the following types of queries:
- Logical
ORqueries. In this case, you should create a separate query for eachORcondition and merge the query results in your app.
Source: Query limitations
Edit:
So I think you could do something like this:
Future<List<DocumentSnapshot>> getPostsToday() async {
final collection = Firestore.instance.collection("Data");
// separate query for each OR condition
final querySnapshots = await Future.wait([
collection.where("test", isEqualTo: 1).getDocuments(),
collection.where("test", isEqualTo: 2).getDocuments(),
collection.where("test", isEqualTo: 4).getDocuments(),
]);
// merge the query results and return
return <DocumentSnapshot>[
...querySnapshots[0].documents,
...querySnapshots[1].documents,
...querySnapshots[2].documents,
];
}
来源:https://stackoverflow.com/questions/58191550/flutter-dart-querysnapshot-isequalto-or-operator