根据规则获取文档名称

Jéw*_*ôm' 1 database database-security firebase google-cloud-firestore

我正在寻找在我的 Firestore 数据库中添加规则。规则是如果文档等于request.auth.uid. 我不知道如何在规则中搜索我的文档名称。

这是我缺少这部分的代码:

service cloud.firestore {
  match /databases/{database}/documents {
  match /users/{anyDocument} {
      allow write: if request.auth != null && request.auth.uid == ?????????;
      allow read
    } 
  }
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*ath 5

您的问题不清楚,但我假设您只想强制编写一个 id 等于用户身份验证 id 的文档。

match /users/{anyDocument} {

由于这一行,文档 id 将被设置为变量anyDocument,因此这就是您要检查的内容。

allow write: if request.auth != null && request.auth.uid == anyDocument;