Firebase Security Rules限制用户事件上传数量问题及规则验证
Firestore 规则调整:限制用户事件上传数量
我拥有Events集合与Users集合,用户上传事件时,Event页面会递增Users集合中对应用户的numberOfEvents计数器。我需要将每个用户的事件上传数量限制为10个。
最初编写的无效规则
rules_version = '2'; service cloud.firestore { match /databases/collection/Events{ allow read; allow write: if 50 > get(/databases/collection/Users/$(request.auth.uid)).data.numberOfEvents; } }
调整后的规则(初步验证有效)
rules_version = '2'; service cloud.firestore { // Do not change this match /databases/{database}/documents { // Path to your document match /Users/{doc=**} { allow read; allow write; } match /Events/{doc=**} { allow read; allow write: if get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.numberOfEvents < 50; } } }
目前这个调整后的规则看起来可行,我会进一步测试验证,感谢帮助!
内容的提问来源于stack exchange,提问作者Sondre
相关产品推荐
相关产品推荐

