我想创建一个Web应用程序以解决客观问题的答案。我正在使用Mongodb,必须与以下对象建立关系。
Classes (like lkg, ukg … )
-- Subjects (like Maths, English …)
---- Lessons (like Lesson 1, Lesson 2 …)
------ Chapters (like Chapter 1A, Chapter 1B …)
-------- Questions (Q1, Q2 …. With correct answer and its description)
我已经考虑了以下内容,但是我无法理解我的Lessons收藏的关系。因此,我真的需要帮助来创建具有关系的收藏集。一个可以提出与我不同的解决方案。
"Classes": [
{"id": 01, "name": "Class 1", "slug": "class-1"},
{"id": 02, "name": "Class 2", "slug": "class-2"},
.......
]
"Subjects": [
{"id": 01, "name": "Math", "slug": "math"},
{"id": 02, "name": "English", "slug": "english"},
.......
]
"lessons": [
{
"name": "Lesson 1",
"slug": "lesson-1",
"class_id": 01,
"subject_id": 01,
"chapters": [
{
"name": "Chapter 1A",
"slug": "chapter-1a",
"questions":[
{
"que": "Question 1 here?",
"choices": ["A": "ans 1", "B": "ans 2", "C": "ans 3", "D": "ans 4"],
"answer": "A",
"description": "Solution description will go here....."
},
{
"que": "Question 2 here?",
"choices": ["A": "ans 1", "B": "ans 2", "C": "ans 3", "D": "ans 4"],
"answer": "B",
"description": "Solution description will go here....."
},
............
............
]
},
{
"name": "Chapter 1B",
"slug": "chapter-1b",
"questions":[
{
"que": "Question 1 here?",
"choices": ["A": "ans 1", "B": "ans 2", "C": "ans 3", "D": "ans 4"],
"answer": "A",
"description": "Solution description will go here....."
},
{
"que": "Question 2 here?",
"choices": ["A": "ans 1", "B": "ans 2", "C": "ans 3", "D": "ans 4"],
"answer": "B",
"description": "Solution description will go here....."
},
............
............
]
},
...................
...................
]
},
{
"name": "Lesson 2",
"slug": "lesson-2",
"class_id": 02,
"subject_id": 02,
"chapters": [
{
"name": "Chapter 1A",
"slug": "cahpter-1a",
"questions": [
{
"question": "Question 1 here?",
"choices": [A: "ans 1", B: "ans 2", C: "ans 3", D: "ans 4"],
"answer": "A",
"description": "Solution description will go here....."
},
{
"question": "Question 2 here?",
"choices": [A: "ans 1", B: "ans 2", C: "ans 3", D: "ans 4"],
"answer": "B",
"description": "Solution description will go here....."
},
............
............
]
},
{
"name": "Chapter 1B",
"slug": "chapter-1b",
"questions":[
{
"question": "Question 1 here?",
"choices": [A: "ans 1", B: "ans 2", C: "ans 3", D: "ans 4"],
"answer": "A",
"description": "Solution description will go here....."
},
{
"question": "Question 2 here?",
"choices": [A: "ans 1", B: "ans 2", C: "ans 3", D: "ans 4"],
"answer": "B",
"description": "Solution description will go here....."
},
............
............
]
},
...................
...................
]
},
....................
.......................
]
答案 0 :(得分:0)
是的,我不会实现这种数据结构。这就是在SQL par领域中要做的事情。
相反,将结构弄平,并确保端点包括视图所需的内容,并且没有嵌套的波纹管。
类似的东西:
"lessons": {
"lesson_id_1": {
"name": "Lesson 1",
"slug": "lesson-1",
"class": "Class 1",
"subject": "Math",
"chapters": [
"Chapter 1A"
]
}
},
"questions": {
"lesson_id_1": {
"Chapter 1A": {
"slug": "chapter-1a",
"questions": [{
"que": "Question 1 here?",
"choices": ["A": "ans 1", "B": "ans 2", "C": "ans 3", "D": "ans 4"],
"answer": "A",
"description": "Solution description will go here....."
},{
"que": "Question 2 here?",
"choices": ["A": "ans 1", "B": "ans 2", "C": "ans 3", "D": "ans 4"],
"answer": "B",
"description": "Solution description will go here....."
}]
}
}
}
您可以使用/lessons/lesson_id_1
一次性获得所有课程数据
获取第1课第1A章的问题:/questions/lesson_id_1/Chapter 1A/
-
您想做的是SQL。您需要转变范式,并提出问题,我真正需要在哪里提供哪些数据?