首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebase中的数据结构

Firebase中的数据结构
EN

Stack Overflow用户
提问于 2017-05-09 12:43:54
回答 1查看 73关注 0票数 2

我有我的数据,就像,一个老师和很少有支付选择的学生。

我想把数据结构写在下面。

  1. 通过认证的教师,具有读/写访问学生的简介。
  2. r/w访问认证的学生配置文件。
  3. 发票可读的学生,但是,写访问老师。

在用防火墙中的安全规则构造上面的dB时,寻找输入/帮助。

更新使用下面的示例DB来测试布拉德利的答案。

代码语言:javascript
复制
 {
"invoices" : {
"stid1" : {
  "studentID" : "9EtsXHveIyaEkkLLk5hpo6vCtVx1"
}
},
"students" : {
"3d2HnQUxAbgaOqWBEqfDuhkhkj63" : {
  "name" : "s2"
},
"9EtsXHveIyaEkkLLk5hpo6vCtVx1" : {
  "name" : "s1"
}
},
 "teachers" : {
  "aiBunX1rZceD2lRslEmCrFHS2XF3" : {
  "name" : "s1"
  }
 }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-09 13:15:28

以下数据库规则:

代码语言:javascript
复制
{

"rules": {
    // teachers profiles stored under this node
    // teachers can read and write under their own node
    "teachers": {
        "$teacherID": {
            ".read": "auth != null && auth.uid == $teacherID",
            ".write": "auth != null && auth.uid == $teacherID"
        }
    },
    // teachers can r/w student profiles, and the students can also r/w their own profile
    "students": {
        "$studentID": {
            ".read": "auth != null && (root.child('teachers').child(auth.uid).exists() || auth.uid == $studentID)",
            ".write": "auth != null && (root.child('teachers').child(auth.uid).exists() || auth.uid == $studentID)"
        }
    },
    "invoices": {
        "$invoiceID": {
            // assuming each invoice has the student ID located at /$invoiceID/studentID
            // students can read, teachers can r/w
            ".read" : "auth != null && (root.child('invoices').child($invoiceID).child('studentID').val() == auth.uid || root.child('teachers').child(auth.uid).exists())",
            ".write": "auth != null && root.child('teachers').child(auth.uid).exists()"

        }
    }
}

}

工作于以下数据库:

代码语言:javascript
复制
{ 

"teachers" : { 
    "aiBunX1rZceD2lRslEmCrFHS2XF3" : { 
        "name" : "s1" 
    } 
},

"students" : { 
    "3d2HnQUxAbgaOqWBEqfDuhkhkj63" : { 
        "name" : "s2" 
    }, 
    "9EtsXHveIyaEkkLLk5hpo6vCtVx1" : { 
        "name" : "s1" 
    } 
}, 

"invoice" : { 
    "stid1" : { 
        "9EtsXHveIyaEkkLLk5hpo6vCtVx1" : { 
            "ispaid" : false 
        }, 
        "studentID" : "9EtsXHveIyaEkkLLk5hpo6vCtVx1" 
    } 
} 

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43870173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档