集合中集合的Firebase安全规则

时间:2020-03-20 00:49:51

标签: ios firebase google-cloud-firestore firebase-authentication firebase-security

我正在尝试使用Firebase Firestore为一个集合中的所有集合设置一个Firebase安全规则。我有一个名为Chats的集合,我有两个集合,一个是线程,另一个是用户。所有文档ID都是随机的。

这是我的Firebase数据的样子:

enter image description here enter image description here

我正在尝试为所有聊天,话题和用户设置安全性。因为聊天包含线程集合和用户集合,但是在设置以下规则时:无法正常工作:权限缺失或不足。

// Chats can be read & written by all users
  match /Chats/{document} {
    allow read, create, update, delete, write: if true
  }

我也尝试过:

   match /Chats/{document}/thread/{document1} {
     allow read, create, update, delete, write: if true
    }


   match /Chats/{document}/users/{document2} {
     allow read, create, update, delete, write: if true
    } 

但是它没有用,所以如果有人可以帮助我。

1 个答案:

答案 0 :(得分:1)

您当前的规则仅与/Chats集合中的文档匹配:

match /Chats/{userId} 

要使其也与子集合匹配,必须是:

match /Chats/{document=**} {

另请参阅securing hierarchical data上的Firebase文档,特别是recursive wildcards上的部分。