问题描述
通过在网络上执行firestore runTransaction函数,它在下面发生错误.
by execution of firestore runTransaction function on the web,it occurs error below.
firestore.googleapis.com/v1beta1/projects/myproject/databases/(默认)/documents:commit:1 POST https://firestore.googleapis.com/v1beta1/projects/myproject/databases/(默认)/documents:commit 403
firestore.googleapis.com/v1beta1/projects/myproject/databases/(default)/documents:commit:1 POST https://firestore.googleapis.com/v1beta1/projects/myproject/databases/(default)/documents:commit 403
我只允许每个人更新一个字段,而其他则是登录用户的字段.
i want to allow only update one field for everyone and others are for login user.
因此更新规则将使用下一个.
so update rule uses next.
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"要求写权限不像更新那样分散.
I finally got the reason.'runTransaction' requires write authority not a divided like update.
这篇关于firestore交易引发更新规则错误,该规则仅允许一个特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!