需要检查数组中的值的Firebase规则(安全规则中的contains())

时间:2015-08-20 03:03:10

标签: angularjs firebase

如何在firebase规则中检查数组中的值。我想做这样的事情:

ArrayList

因此,在当前用户的连接节点下,如果friends数组中存在someFriendId,则允许访问。 ' someFriendId'不是friends数组的键,也就是使用firebase push()方法生成的自动ID。

1 个答案:

答案 0 :(得分:6)

一般情况下,avoid arrays in distributed data,并在结构化数据指南中阅读Arrays in Firebase

您无法执行"包含"在Firebase安全规则中。相反,您希望将用户存储为密钥,类似于we demonstrate this use case in the security docs

因此,在您的示例中,唯一的更改是使用用户ID替换数组索引,并将值更改为布尔值(或任何其他有用的值)。然后您的安全规则可以结构化为:

root.child('connections/'+auth.uid+'/friends/'+someFriendId).exists();