gpt4 book ai didi

firebase - Flutter/Dart QuerySnapshot isEqualTo还是运算符?

转载 作者:行者123 更新时间:2023-12-03 03:16:23 26 4
gpt4 key购买 nike

我想问一下集合中是否有一个文档,其“test”字段等于1 2或4。但是很遗憾,我没有找到合适的解决方案。

这是我的方法不幸的是,这在这里不起作用(等于1 | 2 | 4)。是否还是运算符? (|)

Future getPostsToday() async { 
...
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection("Data").where("test", isEqualTo: 1 | 2 | 4 ).getDocuments();
return qn.documents;
}

最佳答案

Cloud Firestore does not support the following types of 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.


资料来源: Query limitations

编辑:

因此,我认为您可以执行以下操作:
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,
];
}

关于firebase - Flutter/Dart QuerySnapshot isEqualTo还是运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58191550/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com