Firebase数据库查询:测试给定值的存在,而无需列出所有值



假设我有一个看起来像这样的firebase数据库。

root
  devices
    00EB4A1
    0008634
  devices_unowned
    00056F3
    000A689

仅在devicesdevices_unowned下列出了单个设备,从来没有两者兼而有之。我需要一种安全的方法,以允许无人机设备成为拥有,而无需公开未拥有的设备列表。

我的移动应用程序的用户可能会偶然发现当前未拥有的设备。我需要它们能够执行诸如" root/devices_unowned/000A689 exists, yes or no?"之类的查询,但不能执行诸如" list all the devices at /root/devices_unowned"之类的查询。

这是可能的吗?

对我来说似乎很可行:

{
  "rules": {
    "devices": {
      "$deviceid": {
        ".read": true
      }
    },
    "devices_unowned": {
      "$deviceid": {
        ".read": true
      }
    }
  }
}

使用这些规则,每个用户都可以读取每个特定设备,但是没有用户(具有管理权限的用户除外)可以读取所有设备的列表。

最新更新