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

Firebase索引未定义错误:Python查询数据存在性失败求助

问题解决步骤

1. 修正安全规则的核心问题

  • 字段名不匹配:你的Python代码查询的是Number(单数),但安全规则里写的是Numbers(复数),必须改成一致的Number。
  • 索引位置错误:错误提示明确要求在/public_access路径下添加索引,但你现在把.indexOn放在了all_users子节点下,需要调整索引的层级位置。

修正后的安全规则:

{
  "rules": {
    "public_access": {
      ".indexOn": "Number",
      ".read": "auth.uid === 'regular_user'",
      ".write": true,
      "all_users": {
        // 保留all_users节点原有配置(如果有需要)
      }
    },
      
    "connection_testing": {
      ".read": true,
      ".write": "auth.uid === 'admin_user'"
    },
    "login_data": {
      ".read": true,
      ".write": true
    }
  }
}

2. 优化查询效率(可选)

既然你只需要判断AAAAAA是否存在,不需要返回完整数据,可以添加limit_to_first(1)减少数据传输量:

ref = db.reference('/public_access/all_users')
snapshot = ref.order_by_child('Number').equal_to('AAAAAA').limit_to_first(1).get()
exists = bool(snapshot)  # 快照非空即表示存在目标标签

额外注意

  • 修改规则后要在Firebase控制台保存并等待几秒同步生效。
  • 确认当前认证用户的uid确实是regular_user,否则.read规则会拦截查询请求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 13:54:53