Edit - nothing is wrong with anything below, I was being an idiot and using an incorrect document ID

我试图从嵌套在另一个集合中的集合中获取文档时收到权限异常 . 我的规则设置如下:

service cloud.firestore {
  match /databases/{database}/documents {
    match /campaigns/{campaignId} {
      allow read, update, delete: if request.auth.uid == resource.data.owner;
      allow create: if request.auth.uid != null && request.auth.uid == request.resource.data.owner;

      function parentDoc() {
         return get(/databases/$(database)/documents/campaigns/$(campaignId)).data;
      }

      match /scenes/{sceneId} {
        allow read, write: if parentDoc().owner == request.auth.uid;
      }
    }
  }
}

根据我的理解,这应该允许用户访问嵌套在广告系列中的场景,只要他们签名的auth uid等于父广告系列上的“所有者”参数即可 . 查询广告系列中的所有场景时,此方法正常 . 我现在想要做的是从场景中检索特定文档 . 我获取文档的代码(Android,Java)如下所示:

db.collection("campaigns")
  .document(campaignId)
  .collection("scenes")
  .document(sceneId)
  .addSnapshotListener(this);

不幸的是,这会导致"PERMISSION_DENIED: Missing or insufficient permissions"异常 . 从阅读文档here我会发现检索特定文档应该符合我现在的规则:

此行为适用于从集合中检索一个或多个文档而不是单个文档检索的查询 . 使用文档ID检索单个文档时,Cloud Firestore将使用您的安全规则和实际文档属性读取文档并评估请求 .

所以看起来我必须误解某些东西或者出错了 .

Edit - This query works fine with the current rules:

db.collection("campaigns")
      .document(campaignId)
      .collection("scenes")
      .addSnapshotListener(this);