如何从Firestore获取最新的first?
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有关。
发布于 2020-12-21 20:29:42
我最终解决了这个问题,在Firebase控制台中创建了一个索引,这个方法工作得很好,所以现在我先得到最新的索引。
在我的数据库中,我转到索引来创建一个新的索引,添加我的集合名称,然后为字段添加‘类别’-降序和‘时间戳’-降序,单击集合,然后创建索引。
发布于 2020-11-25 23:34:13
如果您有一个带有时间戳的createdAt字段,或者是一个始终递增的值,则可以使用以下命令按该字段的降序获取快照:
stream: FirebaseFirestore.instance
.collection(Strings.factsText)
.orderBy('timestamp', descending: true)
.where(
Strings.category,
whereIn: [Strings.climateChange])
.snapshots(),另请参阅Query.orderBy method上的FlutterFire文档。
https://stackoverflow.com/questions/65007153
复制相似问题