我在不知道檔案 ID 的情況下更新欄位時遇到問題。在我的應用程式中,我有一個包含用戶帖子的集合名稱 myPost,我想編輯用戶的評論,所以我使用 where 查詢來訪問檔案并且我到達了它,但我不知道如何更新它的欄位。這是我嘗試撰寫的編輯方法,如果有人可以提供幫助,我將不勝感激。
void editReview({required String newRev, required String oldRev}) {
emit(EditReviewloaded());
FirebaseFirestore.instance
.collection('Users')
.doc(uId)
.collection("MyPost")
.where('review', isEqualTo: oldRev)
.get()
.then((value) => value.docs.forEach((element) {
element.data()['review'] = newRev; //not working
emit(EditReviewdone());
}));
}
uj5u.com熱心網友回復:
您可以使用 element.id 獲取檔案的 id
FirebaseFirestore.instance
.collection('Users')
.doc(uId)
.collection("MyPost")
.where('review', isEqualTo: oldRev)
.get()
.then((value) => value.docs.forEach((element) {
element.id
}));
并用這個方法更新它
FirebaseFirestore.instance
.collection('Users')
.doc(uId)
.collection("MyPost")
.doc(docPostId).update({'review': newRev});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/520398.html
標籤:Google Cloud Collective 数据库扑火力基地镖
上一篇:將資料轉換為1NF
