gpt4 book ai didi

firebase - flutter 和 Firestore : How do I get the most recent first?

转载 作者:行者123 更新时间:2023-12-05 01:32:59 29 4
gpt4 key购买 nike

如何从 Firestore 获取最新的第一个?

FirebaseFirestore.instance.collection(Strings.factsText)
.where(
Strings.category,
whereIn: [Strings.climateChange])
.orderBy('timestamp', descending: true)
.snapshots(),

...
final factsDocs = snapshot.data.documents;
return FactsListContainer(factsDocs: factsDocs);
});

当与 .orderBy 一起使用时,问题似乎出在 .where 上!

最佳答案

如果您有一个带有时间戳的 createdAt 字段,或者一个始终递增的值,您可以按该字段的降序获取快照:

stream: FirebaseFirestore.instance
.collection(Strings.factsText)
.orderBy('timestamp', descending: true)
.where(
Strings.category,
whereIn: [Strings.climateChange])
.snapshots(),

另请参阅 Query.orderBy method 上的 FlutterFire 文档.

关于firebase - flutter 和 Firestore : How do I get the most recent first?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65007153/

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