Firebase 为什么firestore不允许访问阵列检查安全规则

Firebase 为什么firestore不允许访问阵列检查安全规则,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,我需要一份这样的清单 clients/{clientId}/points/{pointId} 这个文档中的字段类似于 point aaaa = { device: '1234', messages: 2, color: 'red'... }, point bbbb = { device: 'AAAA', messages: 2, color: 'red'... }, 用户在令牌中具有clientId和设备数组 { uid: 'abc', token: { cli

我需要一份这样的清单

clients/{clientId}/points/{pointId}

这个文档中的字段类似于

point aaaa = { device: '1234', messages: 2, color: 'red'... },
point bbbb = { device: 'AAAA', messages: 2, color: 'red'... },
用户在令牌中具有clientId和设备数组

{
    uid: 'abc',
    token: {
        clientId: 'test1',
        devices: ['1234']
    }
}
我的安全规则是这样的

service cloud.firestore {
  match /databases/{database}/documents {
    match /clients/{clientId} {
      match /visible/{document=**} {
        allow read: if request.auth.token.clientId == clientId
      }
      match /points/{$pointId} {
        allow read, write: if request.auth.token.clientId == clientId && resource.data.device in request.auth.token.devices;
      }
    }
  }
}
所以,如果我直接得到aaa点,它将起作用,但如果我想得到所有的点,如

firestore.ref('path/to/points')。其中('color','=','red')

我被拒绝访问


因此,我如何获得允许我查看的所有点(将以千计)。

这里的问题是安全规则不是过滤器。根据报告:

在编写查询以检索文档时,请记住安全性 规则不是过滤器-查询是全部或无。为了节省你的时间和精力 资源,云Firestore根据查询的潜力评估查询 结果集,而不是所有字段的实际字段值 文件。如果查询可能返回 客户端没有读取权限,整个请求失败


因此,如果整个查询可能无法读取结果集中的某些文档,则整个查询将失败。听起来您的查询并不是专门返回用户可以与自定义声明一起阅读的文档。

您确定自定义声明可以包含列表值吗?我找不到证实或否认这一点的信息。当我从前端记录它时,它是一个数组值。模拟器还支持输入字符串数组。我还尝试将列表存储在不同的路径中,并在get(/documents/../path/to/user/devices)中执行
resource.data.device,其工作方式与为methis发布的方法相同,非常有用,谢谢。如果我像这样展开查询``querys=devices.map(did=>query.where('device','=',did)),然后组合结果,我就可以得到我的预期行为。如果您编辑您的答案来解释多重查询并组合结果,我会将其标记为已接受。@matthewdaniel这远远超出了您的问题范围。如果您有后续问题,请询问另一个问题。