首页 > 解决方案 > 检查项目是否存在于 Firebase 安全规则的子集合中

问题描述

我在使用 firebase 安全规则模拟器时遇到问题,我无法读取字段是否存在。我的结构如下,其中 meta 是团队的子集合,每个团队都在团队集合中。

{
  "teams": {
    <TEAM_ID>" {
      "name": "Team One"
      "meta": {
        "users": [<SOME USER UID>],
        "admins": [<SOME UID>]
      }
    }
  }
}

基本上,我只希望他们能够读取 meta.users 中是否有用户 ID。

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /teams/{teamId} {
     allow read: if exists(/databases/$(database)/documents/teams/$(teamId)/meta/users/$(request.auth.uid))
   }
  }
}

但上述规则返回以下错误。

运行模拟时出错 - 错误:simulator.rules 行 [5]、列 [21]。找不到函数错误:名称:[存在]。

标签: firebasefirebase-security

解决方案


推荐阅读