【问题标题】:validate if the newData is an array with firebase database rules验证 newData 是否是具有 firebase 数据库规则的数组
【发布时间】:2017-12-30 17:13:00
【问题描述】:

有没有办法验证 newData 是否是 firebase 规则中的数组? 类似:

"node" : { ".validate" : "newData.isArray()" }

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-security


    【解决方案1】:

    没有规则检测数据是否为数组。

    Firebase 本身不存储数组。相反,它将数据存储为常规 JSON 对象,以数字作为键。所以

    ["one", "two", "three"]
    

    存储为:

    "0": "one"
    "1": "two"
    "2": "three"
    

    您可以检查数据是否有子0

    ".validate" : "newData.child("0").exists()"
    

    但这又是有经验的 Firebases 通常不建议使用数组的众多原因之一。更多原因请参见this blog post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 2020-05-10
      • 2018-08-25
      相关资源
      最近更新 更多