【发布时间】:2019-07-25 13:21:58
【问题描述】:
我必须使用事务来设置和更新 Firestore 中的某些数据。如果旧数据已经存在,我想合并新数据。这在没有交易的情况下是可能的,但有了它们我似乎做不到,即使它说你可以。
从 Flutter Firestore 实现中,我可以看到以下文档:
/// Writes to the document referred to by the provided [DocumentReference].
/// If the document does not exist yet, it will be created. If you pass
/// SetOptions, the provided data can be merged into the existing document.
Future<void> set(
///.....
我在 Google 上搜索了 SetOptions 类,它在理论上确实存在 (https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/SetOptions),但我似乎找不到任何 Flutter 示例,而且它似乎不存在于 Flutter 版本中lib,也不是这个方法的参数。
这是我当前的交易调用:
transaction.set(doc.reference, {
"liked": FieldValue.arrayUnion([entryInfo.id]),
});
是否可以在 Flutter 版本的 Firestore 中执行此操作,或者这是一个错误并且尚未实现?
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore