Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅授予对Firebase中具有特定值的数据的读取权限?_Firebase_Firebase Security - Fatal编程技术网

如何仅授予对Firebase中具有特定值的数据的读取权限?

如何仅授予对Firebase中具有特定值的数据的读取权限?,firebase,firebase-security,Firebase,Firebase Security,以下是Firebase中的数据结构: { "wall" : { "-cxwcxwcxw" : { "name" : "hello", "status" : 0 }, "-cxwfdscxw" : { "name" : "stack", "status" : 0 }, "-cxfdsqcxw" : { "name" : "overflow", "status"

以下是Firebase中的数据结构:

{
  "wall" : {
    "-cxwcxwcxw" : {
        "name" : "hello",
        "status" : 0
    },
    "-cxwfdscxw" : {
        "name" : "stack",
        "status" : 0
    },
    "-cxfdsqcxw" : {
        "name" : "overflow",
        "status" : 1
    }
  }
}
我只允许读取列表范围中状态为0的wall项。我的意思是获取状态为0的wall项目列表

因此,我的规则是:

{
  "wall": {
    "$wall_item_id": {
       ".read": "data.child('status').val() === 0"
    }
  }
}
出什么事了

编辑:


我已经与模拟器进行了检查,无法访问列表,但我可以访问项目本身(其中status==0)

您的规则是正确的,但仅针对单个项目

允许此读取:
https:///wall/-cxwcxwcxw
此读取被拒绝:
https:///wall/-cxfdsqcxw

但Firebase数据库不会过滤掉无法访问的项目。如果用户无法读取列表中的一项,则无法读取整个列表

解决这个问题的一种方法是将不可访问的项目(
状态===1
)移动到它自己的位置

{
  "validWall": {
    "-cxwcxwcxw" : {
        "name" : "hello",
        "status" : 0
    },
    "-cxwfdscxw" : {
        "name" : "stack",
        "status" : 0
    },
   },
   "invalidWall": {
    "-cxfdsqcxw" : {
        "name" : "overflow",
        "status" : 1
    }
   }
}

是的,您是对的,可以访问项目,但不能访问项目列表。我想这会很困难。是的,Firebase数据库不会过滤掉无法访问的项目。如果用户无法读取列表中的一项,则无法读取整个列表。请告诉我我的答案是否有效。保持未应答队列的畅通是很好的。好的,谢谢,请说明这不可能列出带有安全规则的部分项目,这就是答案。我会接受的,没问题!刚刚做了,还提出了一个建议,你可以如何解决这个问题。