如何设置&“.indexOn&"Firebase中的所有子键? [英] How can I set ".indexOn" for all child keys in Firebase?
问题描述
我在Firebase实时数据库中具有以下数据结构.
I have the follow data structure in Firebase Realtime Database.
{
groups: {
$groupid: {
$userid: Boolean
}
}
}
此处 #groupid
和 $ userid
不同.
当ID为"user0"的用户位于组"group0"中时,它将为
Here #groupid
and $userid
vary.
When a user with id "user0" is in the group "group0", it will be
{
groups: {
...
group0: {
user0: true
}
...
}
}
删除用户后,将为 user0:false
.当我向特定用户查询组时, Firebase SDK
显示警告: FIREBASE警告:使用未指定的索引.考虑将/groups的".indexOn":"user0"添加到安全规则中,以获得更好的性能
When the user is removed, it will be user0: false
.
When I query groups with a specific user, Firebase SDK
shows a warning:
FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "user0" at /groups to your security rules for better performance
随着用户ID的变化,我认为所有用户ID都应编入索引.
如何编写相关的安全规则?
As the user id varies, I think all user ids should be indexed on.
How can I write a relevant security rule?
推荐答案
如果要与特定用户一起查询组,最好让用户维护组列表.
If you want to query groups with a specific user, it is better to make a user maintain group list.
{
user-groups: {
user0: {
group0: true,
group1: true
}
}
}
因此,组具有其成员,而用户具有他/她所属的组.
So, a group has its members and a user has groups he/she belongs to.
这篇关于如何设置&“.indexOn&"Firebase中的所有子键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!