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

Firestore使用collectionGroup查询子集合触发权限不足错误,求排查

Firestore collectionGroup查询权限问题

我尝试使用Firestore的collectionGroup查询从数据库中获取events数据,想通过以下方法获取每个association下的所有已发布events:

getEventsWithCollectionGroupQuery(): Observable<Event[]> {
  return this.afs
    .collectionGroup<Event>(EVENTS_COLLECTION, (ref) => ref.where('published', '==', true))
    .get()
    .pipe(
     // 错误在这里触发
      map((snapshot) => {
        return snapshot.docs.map((eventDoc) => {
          const associationId = eventDoc.ref.parent.parent?.id;
          return {
            ...eventDoc.data(),
            id: eventDoc.id,
            association: associationId,
          };
        });
      })
    );
}

补充说明:

  • 我清楚collectionGroup查询会返回所有名称匹配指定集合ID的集合;
  • 我有两个名为events的集合,一个是顶层集合,另一个是associations/{association=**}/events下的子集合。

逻辑上我觉得没问题,但运行前端代码并订阅时触发错误:
Firestore error: FirebaseError: Missing or insufficient permissions.

我已经为两个集合设置了allow read: true规则,实在搞不懂为何出现此错误。想问下有没有其他可能的问题,还是确实是Firestore规则导致的?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 20:37:36