Firebase实时数据库安全规则获取子名称

问题描述 投票:0回答:1

有没有办法得到孩子的名字?结构如下:

appointment-
           |- "here_is_some_date"-
                                 |-"some_user_id"-
                                                 |-details about it

我需要为谁可以阅读“约会”定义规则,但我不知道如何获取日期的名称,以便我可以访问UID。这就是我尝试过的:

"appointments": {
        ".read": "data.child(data.val()).child(auth.uid).val() === auth.uid"
      }
firebase firebase-realtime-database firebase-security-rules
1个回答
1
投票

在Firebase安全规则中读取子节点值的唯一方法是,如果您知道从当前节点(定义规则的位置)到子节点的确切路径。

因此,如果你知道日期和UID(你肯定都知道),你可以通过以下方式读取子节点的值:

"appointments": {
  ".read": "data.child('here_is_some_date').child('some_user_id').val() === auth.uid"
}

但是在这条道路上没有办法使用通配符。说一下你正在尝试实现的用例有点难,但是如果它“允许用户读取他们预约的约会日期”,那么这将需要一个额外的倒置数据结构:

"user_appointment_dates": {
  "uid1": {
    "date1": true // or a more complete structure with the actual appointments
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.