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

能否为Cloud Firestore中的每个集合单独配置安全规则?

问题核心原因

你的Firestore安全规则文件存在语法结构错误,Firestore解析规则失败后会默认触发全局拒绝策略,因此所有操作都被拦截。

具体错误点

  • 作用域错误:你最后编写的两组/business、/orders集合匹配规则,完全写在了service cloud.firestore以及match /databases/{database}/documents的作用域之外,属于无效代码,直接导致整个规则文件语法校验不通过。
  • 冗余闭合符号:规则文件末尾多了2个多余的}闭合符号,进一步加重语法错误。
  • 语义冗余(非报错原因,可优化):write权限本身已经覆盖create、update、delete三类操作,不需要单独罗列,重复书写不会触发错误但会增加规则冗余度。

修正后的规则示例

rules_version = '2';
service cloud.firestore {
    match /databases/{database}/documents{
        match /users/{user} {
            allow read, write: if request.auth != null;
        }
        match /productos/{product} {
            allow read;
            allow write: if request.auth != null;
        }
        match /business/{business} {
            allow read;
            allow write: if request.auth != null;
        }
        match /orders/{order} {
            allow read;
            allow write: if request.auth != null;
        }
    }
}

修正后规则会按照你预期的逻辑生效:所有集合支持未登录读、登录用户可读写。


内容的提问来源于stack exchange,提问作者JuanPineda115

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 01:27:00