验证 newData 是否为具有 firebase 数据库规则的数组

validate if the newData is an array with firebase database rules

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

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

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

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

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

存储为:

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

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

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

但这又是经验丰富的 Firebase 用户通常不建议使用数组的众多原因之一。有关更多原因,请参阅 this blog post