firebase - 如何通过安全规则禁止更新 Firestore 文档中的特定字段?
问题描述
我有一个事件文档,其中包含标题、位置、容量、坐标等字段。我想设置允许更新文档的安全规则,但如果用户尝试更改容量字段,则会拒绝请求
那么如何编写这样的安全规则呢?我可以这样做吗?
service cloud.firestore {
function admin() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true
}
match /databases/{database}/documents {
match /events/{eventId} {
allow update: if // (allow if user not trying to update capacity field) ???
}
}
}
解决方案
将请求的文档更新的内容与现有内容进行比较,以确保它没有改变:
allow update: if request.resource.data.capacity == resource.data.capacity;
request.resource是传入请求的文档。 资源是现有数据。
推荐阅读
- build - 为一组选定的项目执行选定的 ant 任务
- redmine - 通过bitnami安装后Redmine无法启动
- angular - 截断字符串杀死了我的悬停工具提示,如何取回它(角度)
- ios - Scroll to specific slide/website when button is pressed
- python - Pandas Pivot 创建 NaN
- r - 如何将集合运算表达式编程为函数的参数?
- html - 如何将会话变量传递给 play framework/scala 中的表单以存储在数据库中
- arm - 在 Atmel SAMD51 上配置内存保护单元
- parameters - 如果 Crystal Reports 中的参数值为空,则禁止显示页脚
- c# - 当.Net Thread没有名称时,如何使用NLog打印threadid而不是threadname?