作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试更新我的 Firestore 数据库。这是一个聊天数据库,如果聊天消息已读或未读,我会尝试更新聊天消息,这是我的代码
updateIsread(String receiverId, String chatRoomId) async {
FirebaseFirestore.instance
.collection("chatRoom")
.doc(chatRoomId)
.collection("chats")
.where('sendTo', isEqualTo: receiverId);
}
问题是在
之后.collection("聊天") 我不能用
.update()
最佳答案
您可以尝试获取 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/
我是一名优秀的程序员,十分优秀!