firebase - Firestore 安全规则:检查地图列表的值
问题描述
一个文件看起来像这样
matches: [
{uid: ___ , ...},
{uid: ___ , ...},
]
如何检查请求此操作的用户的 uid 是否在匹配的 uid 之一中?我试过了,但没有用。
输入get(/databases/$(database)/documents/users/$(request.auth.uid)).data.matches.uid
谢谢你的帮助!
解决方案
你不能。安全规则语言不支持for
循环或类似map
. 您需要以不同的方式存储数据。这些模式中的任何一个都可以工作:
// data structure
matches: ["uid1", "uid2", "uid3"]
// rules
allow: if uid in resource.data.matches;
// data structure
matches: {"uid1": true, "uid2": true}
// rules
allow: if resource.data.matches[uid] == true;
或者,如果您知道matches
数组的长度永远不会超过五个元素,您可以手动扩展语句:
allow: if resource.data.matches[0].uid == uid ||
resource.data.matches[1].uid == uid ||
// ...repeat three more times
推荐阅读
- sql-server - 在 SSRS 中添加 3 个多个数据集
- javascript - 如何将数组中的值推送到 chrome 存储中?
- python - Tkinter 包几何管理器 - 选项
- c# - c# NLog local-ip cached
- cordova - 在 Cordova 中打开外部链接而不丢失会话
- bash - 为什么 bash 在测试语法错误时不退出?
- node.js - ES6 Async/Await、ExpressJS 和 Postgres 事务
- javascript - 如何将“Enter”添加到 Tiny MCE 自定义快捷键组合?
- python-3.x - snakemake - 用匿名函数替换输入指令中的通配符
- python - 如何创建一个比使用python创建它的过程寿命更长的环境变量?