You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 02:25:17