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

Firestore CollectionGroup查询权限被拒问题排查求助

Firestore Collection-Group 查询权限拒绝问题排查

问题背景

今年3月在Frank van Puffelen的帮助下,成功配置了Firestore单字段collection-group查询的索引,该查询长期可用。约4周前另一处同类型查询失效,经Doug Stevenson指导得知Google调整了collection-group查询配置,按照官方文档修改后恢复正常。但今日原本正常的主查询也失效,按文档调整安全规则后仍无济于事。

Flutter 代码实现

void signUserIn() async {
      try {
        // try sign-in
        await _auth.signInWithEmailAndPassword(
            email: emailControl.text.trim(),
            password: passwordControl.text.trim());

        // if sign-in succeeds: confirm user's registered-date
        if (_auth != null) {
          await _dB
              .collectionGroup('signInData')
              .where('firebaseUserID', isEqualTo: _auth.currentUser!.uid)
              .get()
              .then((QuerySnapshot querySnapshot) {
            querySnapshot.docs.forEach((doc) {
              registeredDate = doc['registeredDate'];
              print(doc['registeredDate']);
            });
          });
        }

Firestore 索引配置

  • 索引1:针对collection-group signInData,配置了firebaseUserID(升序)与__name__(升序)的复合索引,状态为已启用
  • 索引2:针对collection-group signInData的另一项索引配置,包含firebaseUserID字段

Firestore 安全规则

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

match /{path=**}/signInData/{options1} {
                  allow create;
                    allow read, write, get, update: if request.auth != null;
                } 

       }
}

错误信息

W/Firestore(16490): (24.7.0) [Firestore]: Listen for Query(target=Query( collectionGroup=signInData where userID==XXXXXXXXXXXXXXXXXXX order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter (16490): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.

求助内容

想了解问题所在,以及Google是否再次更新了collection-group查询配置,恳请协助。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 02:06:09