【发布时间】:2016-10-04 23:59:27
【问题描述】:
在 Firebase 指南中,建议之一是维护反向索引以跟踪用户操作。这是我所指的sn-p:
// An index to track Ada's memberships
{
"users": {
"alovelace": {
"name": "Ada Lovelace",
// Index Ada's groups in her profile
"groups": {
// the value here doesn't matter, just that the key exists
"techpioneers": true,
"womentechmakers": true
}
},
...
},
"groups": {
"techpioneers": {
"name": "Historical Tech Pioneers",
"members": {
"alovelace": true,
"ghopper": true,
"eclarke": true
}
},
...
}
}
每个用户都在反向索引中跟踪他/她的组 - 在这种情况下,这意味着键保存实际值,而值无关紧要。
更新
我不确定如何在技术上更新索引,但经过一番研究后我得到了它:setValue 可以接受所有变量,而不仅仅是键值对。这意味着更新索引非常简单:只需获取对 groups/$group_id/members/$member_id 的引用并将其值设置为 true。
现在我的问题不同了:
假设所有组都是私有的。这意味着用户只能通过邀请加入群组 - 当前群组成员必须将另一个用户添加到成员列表中。因此,如果我是 ghopper 并且我想将 alovelace 添加为成员,我需要更新她的索引,该索引是她的用户对象的一部分 - 这意味着我必须知道她的用户 ID 以某种方式对她的groups 字段具有写访问权限 - 这似乎存在安全风险。
对于如何在尽可能限制访问的同时管理此问题有什么想法吗?可能是另一个将用户已知标识符(如电子邮件)映射到组列表的数据库对象?
【问题讨论】:
-
试试firebase的multi-path-updates
标签: json indexing firebase firebase-realtime-database firebase-security