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 Realtime Database_Firebase Security - Fatal编程技术网

为什么这两套相同的Firebase规则的工作方式非常不同?

为什么这两套相同的Firebase规则的工作方式非常不同?,firebase,firebase-realtime-database,firebase-security,Firebase,Firebase Realtime Database,Firebase Security,这组规则运行良好,并按预期输出 { "rules": { "intents" : { ".read" : "auth.uid === data.child('to').val()", ".write" : true }, "messages" : { ".read": "auth.uid !== null", "$message": { ".write": true } } } } 但是,这组规则不允许任何用户读取

这组规则运行良好,并按预期输出

{
"rules": {
  "intents" : {
    ".read" : "auth.uid === data.child('to').val()",
    ".write" : true
  },
  "messages" : {
    ".read":  "auth.uid !== null",
    "$message": {
           ".write": true
    }
  }
}
}
但是,这组规则不允许任何用户读取任何数据,尽管写入操作在这组规则中也可以正常工作

{
"rules": {
  "intents" : {
    ".read" : "auth.uid === data.child('to').val()",
    ".write" : true
  },
  "messages" : {
    "$message": {
           ".read":  "auth.uid !== null",
           ".write": true
    }
  }
}
}
对我来说,这两套看起来几乎一模一样。是否有我遗漏的“Firebase安全规则”规则?


注意这两条规则都在未对数据库或任何代码进行任何更改的情况下进行了测试。只有显示的规则被更改。

这两组规则有一个重要区别:第一组允许在一次操作中读取“消息”,而另一组只允许一次读取任何单个消息。您可能试图在一个操作中读取所有消息,只有第一条规则允许您这样做

{
  "rules": {
    ...
    "messages" : {
      ".read":  "auth.uid !== null", // Here: Can read all at once
      "$message": {
        ".read":  "auth.uid !== null", // Here: Can only read one at a time
        ".write": true
      }
    }
  }
}

我正在使用android中的RecycleServiceAdapter来阅读消息。但在第二种情况下,我连一条消息都看不懂,尽管在第一种情况下,该应用程序运行良好,并能正确显示所有消息。我从未听说过RecycleServiceAdapter。它是如何为你传递信息的?你确定它没有尝试读取所有消息吗?即使它一次读取所有消息,它是否应该至少显示一条消息,如你所说的情况2?不,在第二种情况下,如果你尝试直接读取该消息,则只能读取消息。例如,您可以从
ref.(child)。('messages').child(messageId)
读取,但不能从
ref.child('messages')
读取。从根目录到“messages”并包括“messages”进行搜索时,没有允许读取的
.read
规则。那么,如何以我想要的方式读取消息呢?i、 e.最初,所有现有的消息,然后在新消息到达数据库时逐个发送。;