1

我是 NoSql 数据库的新手,我很难弄清楚如何处理本地驱动器上可能超过 20MB 的非常大的 JSON 文档。这种结构肯定会随着时间的推移而增加,我担心查询的速度以及必须通过返回的 JSON 对象嵌套进行深入搜索才能得到一个字符串。例如,我的 JSON 嵌套很深。

{
"exams": {
    "exam1": {
        "year": {
            "math": {
                "questions": [
                    {
                        "question_text": "first question",
                        "options": [
                            "option1",
                            "option2",
                            "option3",
                            "option4",
                            "option5"
                        ],
                        "answer": 1,
                        "explaination": "explain the answer"
                    },
                    {
                         "question_text": "second question",
                        "options": [
                            "option1",
                            "option2",
                            "option3",
                            "option4",
                            "option5"
                        ],
                        "answer": 1,
                        "explaination": "explain the answer"
                    },
                    {
                        "question_text": "third question",
                        "options": [
                            "option1",
                            "option2",
                            "option3",
                            "option4",
                            "option5"
                        ],
                        "answer": 1,
                        "explaination": "explain the answer"
                    }
                ]
            },
            "english": {same structure as above}
        },
        "1961": {}
    },
    "exam2": {},
    "exam3": {},
    "exam4": {}
}
}

在主应用程序中,根据考试类型、年份和主题创建和附加问题对象,使 JSON 文档随着时间的推移变得庞大。我该如何重新建模以避免将来查询缓慢?

4

1 回答 1

0

多米尼克是对的。您需要开始分割文档并将它们存储为单独的文档。

下一个问题是如何在拆分后重新组合文档。

考虑到您使用的是 Couch,我建议您在应用程序层执行此操作。一个好的起点是创建考试文档并将它们存储在自己的数据库中。然后在另一个数据库中有一个文档(考试),其中包含指向考试文档的指针。

您可以根据需要检索考试文档并进行考试。这对于分页尤其有用,因为大多数人只想查看最近的考试。

于 2013-10-14T15:45:18.730 回答