【发布时间】:2022-01-03 17:03:10
【问题描述】:
我正在尝试运行一个查询,该查询在给定 where 子句的情况下检索单行并更新它。我了解 Firebase 不支持 UpdateWhere 操作,因此我尝试改用 Transaction。
我很难让它工作,也许我太习惯 sql dbs... 这是我的坏代码
try {
final whereQuery = _db
.doc(userPath(user))
.collection("someInnerCollection")
.where("active", isEqualTo: true)
.limit(1);
await _db.runTransaction((transaction) async {
final entry = await transaction.get(whereQuery); // This doesn't compile as .get doesn't take in a query
await transaction.update(entry, {
"someValue": "newValue",
});
});
} catch (e) {
...
}
【问题讨论】:
标签: firebase flutter google-cloud-firestore