Gal*_*cha 9 firebase firebase-security google-cloud-firestore
在Cloud Firestore规则中 - 我有一个调用的文档task,我想查看某些数据(assignee字段)是否为空/不存在.
我试过了:
resource.data.assignee == null - 不起作用(错误)!resource.data.hasAll(['assignee']) - 不起作用(错误)从文档中 - 它表明这确实会产生错误:
// Error, key doesn't exist
allow read: if resource.data.nonExistentKey == 'value';
Cal*_*lam 20
阅读公司的FireStore安全规则文档的列表比较在这里,我们可以看到,hasAll如果所有值都出现在列表返回true.
// Allow read if one list has all items in the other list
allow read: if ['username', 'age'].hasAll(['username', 'age']);
Run Code Online (Sandbox Code Playgroud)
这request.resource.data是一个包含字段和值的地图.为了使用hasAll,我们必须先拿到钥匙作为值的列表如图所示这里.
!resource.data.keys().hasAll(['assignee'])
Run Code Online (Sandbox Code Playgroud)
小智 12
查看文档 - https://firebase.google.com/docs/reference/rules/rules.Map
k in x - Check if key k exists in map x
Run Code Online (Sandbox Code Playgroud)
所以这应该工作(没有键())
!('assignee' in resource.data)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4928 次 |
| 最近记录: |