我试图更新我的firestore数据库字段。
Future<void> approveJob(String categoryId) {
注释行已在数据库上更新。但是我硬编码uid。是否可以不存储而获取uid?
//return _db.collection('jobs').document('25FgSmfySbhEPe1z539T').updateData({'isApproved':true});
return _db
.collection('jobs')
.where("categoryId", isEqualTo: categoryId)
.getDocuments()
.then((v) {
try{
v.documents[0].data.update('isApproved', (bool) => true,ifAbsent: ()=>true);
// No Errors. But not updating
}catch(e){
print(e);
}
});
}
最佳答案
为了更新文档中的字段,您只需要遵循this文档即可。
关于如何获取documentID,您可以按照here所述进行操作
另外请记住,您可以update data with transactions。
让我知道这是否有帮助。
关于firebase - 如何使用Flutter更新Cloud Firestore上文档的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58383016/