2
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

firestoreのcollectionGroupのデータ取得で `The caller does not have permission to execute the specified operation.`

firestoreのcollectionGroupを使うと下記のようなエラーが出た

こんな権限エラーが出る…

Error: [firestore/permission-denied] The caller does not have permission to execute the specified operation.

Native Firebase

NativeFirebaseError: [firestore/permission-denied] The caller does not have permission to execute the specified operation.

解決 - セキュリティールールを正しく書き換えよう!

firestore Security Rulesを確認してください。

collectionGroupで下の階層のサブコレクションにアクセスするには
match /{path=**}/コレクション名/{documentId}
の様に上の階層をカスケードしてあげるとPermissionのエラーが消えます!

rules_version = '2';
 service cloud.firestore {
    match /databases/{database}/documents {
      // 認証済み
      function isAuthenticated() {
        return request.auth.uid != null
      }

       // コレクショングループの所
       match /{path=**}/followor_ids/{followerIds} {
        allow read, write: if isAuthenticated();
      }
    }
 }

こんなコードを書いてる時に発生します!


firestore().collectionGroup(COLLECTION_NAME).where('ids', 'array-contains', uid).get()

参考

Collection Group permissions for Firestore - by stackoverflow

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
2
Help us understand the problem. What are the problem?