Firestore filter error: Missing or insufficient permissions

Firestore filter error: Missing or insufficient permissions

我正在使用 Ionic cordova 客户端处理 Firestore 数据库。这是我的数据结构:

我想根据 ownerId 字段过滤我的设计集合。

我尝试了几个规则,但都给了我

Error : Missing or insufficient permissions.

这是我目前的规则

service cloud.firestore {
  match /databases/{database}/documents {
    match /designs/{design} {
      allow read: if resource.data.ownerId == request.auth.uid ;
      allow write: if false;
    }
  }
}

这是我的客户端代码

AngularFirestore.collection(`designs`).snapshotChanges().map(x => {
            return x.map(y => {
              return y.payload.doc.data() ;
            });
        });

这里的问题是规则不能用作过滤器。

如果您尝试阅读单个文档,ownerId == request.auth.id 就可以了。

如果您想列出该用户可读的所有文档,则需要根据当前用户 ID(此处显示为 userId)进行过滤:

AngularFirestore.collection(`designs`).where('ownerId', '==', userId).snapshotChanges().map(x => {
            return x.map(y => {
              return y.payload.doc.data() ;
            });
        });