如何以只读模式查询firebase

How to query firebase in readonly mode

我在 firebase 中有一些数据要查询。我的 firebase 具有只读的默认安全设置。但是当我尝试如下查询数据时

this.firestore.collection('myCollection').valueChanges().pipe().subscribe(x => {
  console.log;
});

this.firestore.collection('myCollection').get().subscribe(x => {
  console.log;
});

我确实收到了一个错误 Missing or insufficient permissions. 根据我的轻描淡写,这不应该是这种情况,因为我只是在阅读数据。另外我可能不得不提到我正在使用 @angular/fire

Just for an experiment I did try to enable the write access to database and it works this way but I want to keep the readonly mode.

这是我的规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

有什么想法吗?

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

您不允许只读访问,因为它等同于

....
allow read: if false;   // <- You deny any read here
allow write: if false;
....

您需要按如下方式调整您的规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if true;
      allow write: if false;
    }
  }
}

doc 中的更多信息,包括文档顶部的视频。