如何在阵列包含特定值的地方设置Firestore安全规则

问题描述

我想这样设置规则:当用户的uid包含在城市文档的数组字段中时,该用户具有权限。

我做到了。请告诉我怎么做

allow read : if (city.some-array.contain(uid));

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

    // Match any document in the 'cities' collection
    match /cities/{city} {
      allow read: ***if <condition>;***
      allow write: if <condition>;
    }
  }
}

解决方法

您可以将resource.data(该对象包含操作前的当前数据)与in结合使用以实现此目的。

match /cities/{city} {
    allow read,write: if request.auth.uid in resource.data.authorizedUsers
    // replace authorizedUsers with the name of your array field
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...