【发布时间】:2022-06-13 03:09:32
【问题描述】:
我已经实现了这个代码来检索这个房间的消息。
final messagesProvider = StreamProvider((ref) {
FirebaseFirestore db = FirebaseFirestore.instance;
var room = ref.watch(roomIdProvider);
print('room updated');
print('room is '+room);
final docRef = db
.collection("messages")
.where("chat_room_id",isEqualTo: room)
// .orderBy('created_at')
// .orderBy('created_at',descending: true)
;
print(docRef.orderBy("created_at").snapshots());
return docRef.snapshots();
});
我想对数据进行排序并分别尝试了这两行但对我不起作用
.orderBy('created_at')
.orderBy('created_at',descending: true)
在哪里创建的是一个时间戳字段。
【问题讨论】:
-
这里有一些关于此的示例(order by not returning 和firestore order by),在所有示例中都建议使用索引。你可以关注instructions here来做。
标签: flutter firebase dart google-cloud-firestore riverpod