首页 > 解决方案 > 尝试为 HashMap 引入 Firestore 安全规则并相互同步查询

问题描述

在创建一些 Firestore 安全规则以处理我的代码中的查询时,我需要帮助。所以我尝试使用 HashMap,如下所示,“sharedWith”是我文档中的一个 hashmap 字段:

...
  sharedWith
        abc@gmail.com : true
        zzz@gmail.com : true     
...

我的安全规则我尝试设置如下:

allow read: if isSignedIn() && resource.data.sharedWith[request.auth.token.email]=="true"

我期望发生的是当用户“zzz”登录时,该用户应该能够阅读此文档(由其他用户创建)

我的查询如下:

db.collection("Sites")
        .whereEqualTo("sharedWith."+"zzz.@gmail.com",true)
        .get()
        .addOnSuccessListener { result -> ...

请问我哪里错了?

我得到的错误如下:

侦听查询(sharedWith..com zzz@gmail== true order by name的站点)失败:状态{code=PERMISSION_DENIED,description=Missing 或权限不足。,cause=null}

标签: firebasenosqlgoogle-cloud-firestorefirebase-security

解决方案


推荐阅读