需要为以下内容创建Mongodb集合的帮助吗
我想创建一个web应用程序,用于解决客观问题和答案。我使用的是Mongodb,我必须为以下关系创建集合需要为以下内容创建Mongodb集合的帮助吗,mongodb,Mongodb,我想创建一个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 ans
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)
我想了以下几点,但我无法理解我的课程集之间的关系。所以我真的需要帮助来建立我的收藏关系。人们可以提出与我不同的解决方案
"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....."
},
............
............
]
},
...................
...................
]
},
....................
.......................
]
是的,我不会实现这种数据结构。这是在SQL Par土地上要做的事情。< /P> 取而代之的是,将结构展平,并确保端点包含视图所需的内容,而不是下面嵌套的内容 比如:
"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\u id\u 1
获取第1课第1A章问题:/questions/lesson\u id\u 1/chapter 1A/
--
您试图做的是SQL。您需要改变您的范例,并提出以下问题:我真正需要什么数据?在哪里?我建议的结构只是您展示的关系模型的一个扁平版本,适合您的用例的实际模型将完全取决于它。