如何为我的个人投资组合网站设置Firebase firestore规则?

如何为我的个人投资组合网站设置Firebase firestore规则?,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,这可能是一个很难回答的问题,但我该如何制定规则呢 我已经创建了一个网站,从firestore读取数据,我需要将这些数据保存到任何人都可以读取的位置,但只能由我编辑。这是我尝试的示例代码: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { // Allow public read access, but only content owners can write

这可能是一个很难回答的问题,但我该如何制定规则呢

我已经创建了一个网站,从firestore读取数据,我需要将这些数据保存到任何人都可以读取的位置,但只能由我编辑。这是我尝试的示例代码:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Allow public read access, but only content owners can write
    match /some_collection/{document} {
      allow read: if true
      allow create: if request.auth.uid == request.resource.data.author_uid;
      allow update, delete: if request.auth.uid == resource.data.author_uid;
    }
  }
}

以及:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Allow only authenticated content owners access
    match /some_collection/{userId}/{documents=**} {
        allow read: if true;
      allow write: if request.auth != null && request.auth.uid == userId
    }
  }
}
对于这两种情况,我的网站都无法从数据库接收数据

编辑:显示不工作的查询。我使用vueJS实现了以下目的:

mounted() {
      const db = this.$firebase.firestore();
      let storage = this.$firebase.storage();
      let storageRef = storage.ref().child('images');
      db
        .collection('projects')
        .onSnapshot(snap => {
          const info = [];
          snap.forEach(doc => {
            let data = doc.data();
            let imgName = data.img
            storageRef.child(imgName)
            .getDownloadURL().then((url) => {
              data.img = url
              // console.log(data.img)
            }).catch((error) => {
              // Handle any errors
              console.log(error)
            });
            data.index = doc.id;
            info.push(data);
          });
          this.info = info;
        });
    },

这里的查询是针对集合“projects”的,但您的规则只允许对名为“some\u collection”的集合进行查询。考虑到您也显示的规则,我希望您在这里显示的查询总是失败的。您使用了错误的集合名称,或者您的规则与您试图对查询执行的操作不匹配


此外,一个数据库不能有两套完全不同的规则。所有规则必须在同一集中。

请编辑问题以显示未按预期方式运行的查询。应该清楚的是,该查询将如何受到规则的影响。如果不知道规则要允许的特定查询,规则本身就没有意义。@DougStevenson这就是你要找的吗?谢谢你的帮助!