gpt4 book ai didi

firebase - 如何在firebase firestore中收集后更新数据-flutter

转载 作者:行者123 更新时间:2023-12-04 07:53:51 25 4
gpt4 key购买 nike

我正在尝试更新我的 Firestore 数据库。这是一个聊天数据库,如果聊天消息已读或未读,我会尝试更新聊天消息,这是我的代码

updateIsread(String receiverId, String chatRoomId) async {
FirebaseFirestore.instance
.collection("chatRoom")
.doc(chatRoomId)
.collection("chats")
.where('sendTo', isEqualTo: receiverId);
}
问题是在 之后.collection("聊天") 我不能用 .update()
请帮帮我,这是我的 firebase 结构
enter image description here
enter image description here

最佳答案

您可以尝试获取 QuerySnapshot首先,然后从其中的第一个文档中您可以知道 DocumentReference 并使用 update 在上面:

await QuerySnapshot _querySnapshot = FirebaseFirestore.instance
.collection("chatRoom")
.doc(chatRoomId)
.collection("chats")
.where('sendTo', isEqualTo: receiverId).get();
if (_querySnapshot.docs.isNotEmpty) await _querySnapshot.docs[0]
.reference
.update('YourUpdateData');
可能有更好的方法来做到这一点,但这对我有用。

关于firebase - 如何在firebase firestore中收集后更新数据-flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66806259/

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