Dan*_*ira 5 dart flutter google-cloud-firestore
我的 FireStore 中保存了一份数据,我只需要更新一个字段。
name: "Daniel",
lastname: "Pereira",
age: 25,
isLogged: false
Run Code Online (Sandbox Code Playgroud)
例如,我只需将isLogged更新为true 。
仅传递给 updateDate 一个 json,例如:{"isLogged": true }
final CollectionReference collectionReference = Firestore.instance.collection("profiles");
collectionReference.document("profile")
.updateData({"isLogged": true})
.whenComplete(() async {
print("Completed");
}).catchError((e) => print(e));
Run Code Online (Sandbox Code Playgroud)
如果您使用交易,您可以这样做:
Firestore.instance.runTransaction((transaction) async {
await transaction.update(
collectionReference.document("profile"), {"isLogged": true});
};
Run Code Online (Sandbox Code Playgroud)
希望这对某人有帮助!;)
归档时间: |
|
查看次数: |
4409 次 |
最近记录: |