为什么在尝试从 firestore 中删除数组元素时出现权限不足错误,但我可以删除整个文档

Why do I get an insufficient permissions error while trying to delete an array element from firestore, yet I can delete the entire document

我的 firestore 中有一个名为“reports”的集合

报告映射中的一个字段是一个对象数组。这些对象引用云存储中的照片。它们看起来像这样(url 指向云存储):

{
   id: uid value
   url: some-url
}

我的 firebase 规则是这样为报告文档设置的:

match /databases/{database}/documents {
    match /reports/{report} {
      allow read: if request.auth != null && request.auth.uid == resource.data.userID;
      allow create: if request.auth != null && request.resource.data.userID == request.auth.uid;
      allow delete, update: if request.auth != null &&
      request.auth.uid == resource.data.userID;
    }
}

出于某种原因,如果我想证明我有删除权限,我可以删除整个文档......但是当我尝试从照片数组中删除一个项目时,如下所示:

const reportRef = db.collection('reports')
reportRef.doc(activeReport.id).update({
    photos: firebase.firestore.FieldValue.arrayRemove(photoToDelete)
})

我以错误告终:

Unhandled promise rejection: FirebaseError: Missing or insufficient permissions

为什么?我没有授权正确更新此文档吗?

进入数据库 -> 规则 ->

开发用:

allow read, write: if false; 更改为 true;

Note: It's a quick solution for development purposes only because it will turn off all the security. So, it's not recommended for production.

用于生产:

如果从 firebase 进行身份验证:Change allow read, write: if false;request.auth != null;

在这种情况下,这是传入的错误参数。我需要传递 activeReport 而不是 activeReport.id。

这是误导性的错误信息。我会删除这个问题,但 Whosebug 不希望我这样做,因为这里已经发布了答案。傻.