小编R S*_*R S的帖子

在事务中访问新文档时 Firestore 安全规则?

我正在运行以下 Firestore 事务以在accounts集合中创建一个新文档并将其新创建的 ID 添加到用户的accounts. (相反,members发送到帐户的对象包含用户 ID。)

db.runTransaction(transaction => {
    return transaction.get(db.collection('accounts').doc())
        .then(res => {
            const accountId = res.id;
            transaction.set(db.collection('accounts').doc(accountId), {name, numberOfEmployees, businessTypes, industry, members})
            transaction.set(db.collection('users').doc(uid), {accounts: {[accountId]: true}}, {merge: true})
            return accountId;
        }, error => error)
})
Run Code Online (Sandbox Code Playgroud)

.collection('accounts').doc()我正在使用没有路径返回新文档的事实,但我遇到了Missing or insufficient permissions.错误。我的规则如下:

service cloud.firestore {
  match /databases/{database}/documents {

    match /users/{userId} {
      allow read, write: if request.auth.uid == userId;
    }

    match /accounts/{accountId} {
        // allow read if user is a …
Run Code Online (Sandbox Code Playgroud)

javascript firebase-security google-cloud-firestore

3
推荐指数
1
解决办法
1095
查看次数