gpt4 book ai didi

firebase - firestore 事务抛出更新规则错误,该规则只允许有一个特定字段

转载 作者:行者123 更新时间:2023-12-05 07:29:54 25 4
gpt4 key购买 nike

通过在网络上执行 firestore runTransaction 函数,出现以下错误。

firestore.googleapis.com/v1beta1/projects/myproject/databases/(默认)/documents:commit:1 POST https://firestore.googleapis.com/v1beta1/projects/myproject/databases/(default)/documents:commit 403

我只想允许每个人更新一个字段,其他字段用于登录用户。

所以更新规则使用下一个。

allow update: if request.resource.data.keys().hasOnly(["numPlayed"]) 
|| request.auth.uid != null;

和交易代码如

this.db.runTransaction(function(t) {
return t.get(pubRef)
.then(function(pub) {
var numPlayed = pub.data().numPlayed + 1;
t.update(pubRef, { numPlayed: numPlayed });
return numPlayed;
});
})

为什么会报错?

最佳答案

我终于明白了。'runTransaction' 需要写入权限而不是像更新一样划分。

关于firebase - firestore 事务抛出更新规则错误,该规则只允许有一个特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52523941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com