OpenEDX课程数据的存储方式

OpenEDX课程数据的存储方式在官方文档中Split Mongo Modulestore一节说明了其设计的核心思想,本文简单解释一下它的存储方式并通过查看数据库存储的内容来进一步了解它。

每个课程的数据都分三部分:

  • Course Index 课程最基本的数据,比如课程代码、单位等,其中最重要的是两个ObjectID,一个是已发布的课程Course Structures,另一个编辑中的课程Course Structures
  • Course Structures,记录着课程的主要内容和结构,包含多个block,其中默认包含course和overview两个block,所有的block都有自己的ObjectID,它指向XBlock Definitions
  • XBlock Definitions 记录block的具体数据。

下面是mongodb中的collections

root@i-7kvy76cm:/edx# mongo
MongoDB shell version: 2.6.11
connecting to: test
> use edxapp
switched to db edxapp
> show collections
fs.chunks
fs.files
modulestore.active_versions # 即是Course Index
modulestore.definitions # 即是XBlock Definitions
modulestore.structures # 即是Course Structures
system.indexes

modulestore.active_versions中的数据大致是这样

{
 "_id": ObjectId("5632e46950e3432ed9f51b08"),
 "course": "test10code", # 课程代码
 "edited_on": ISODate("2015-10-30T03:30:49.380Z"),
 "run": "2015",
 "versions": {
 "draft-branch": ObjectId("5632e46950e3432ed9f51b07"),# 编辑版Course Structures
 "published-branch": ObjectId("5632e46950e3432ed9f51b09")
 }, # 发布版Course Structures
 "search_targets": {
 "wiki_slug": "test10org.test10code.2015"
 },
 "org": "test10org", # 单位代码
 "edited_by": NumberLong(9),
 "schema_version": 1,
 "last_update": ISODate("2015-10-30T03:30:49.564Z")
}

Course Structures的json数据大致是这样:

{
 "_id": ObjectId("5632e84650e3432ed9f51b0b"),
 "edited_by": NumberLong(9),
 "previous_version": ObjectId("5632e83550e3432edcf51b07"),
 "original_version": ObjectId("5632e46950e3432ed9f51b07"),
 "schema_version": 1,
 "edited_on": ISODate("2015-10-30T03:47:18.352Z"),
 "blocks": [ # blocks列表,第一个是新添加一个章节数据test-chapter1
 {
 "definition": ObjectId("5632e83550e3432edcf51b06"),
 "block_type": "chapter",
 "block_id": "7270a053884041a2b2cc0e64065970f2",
 "fields": {
 "display_name": "test-chapter1"
 },
 "defaults": {

 },
 "edit_info": {
 "edited_by": NumberLong(9),
 "previous_version": ObjectId("5632e83550e3432edcf51b07"),
 "original_usage_version": null,
 "original_usage": null,
 "edited_on": ISODate("2015-10-30T03:47:18.352Z"),
 "source_version": null,
 "update_version": ObjectId("5632e84650e3432ed9f51b0b")
 }
 },
 { # 第二是默认存在的基本course的block,它设定了课程包含哪几大块内容,比如课件、更新通知、教材、论坛、wiki等
 "definition": ObjectId("5632e46950e3432ed9f51b06"),
 "block_type": "course",
 "block_id": "course",
 "fields": {
 "display_name": "test10name",
 "language": "en",
 "tabs": [
 {
 "type": "courseware",
 "name": "Courseware"
 },
 {
 "type": "course_info",
 "name": "Course Info"
 },
 {
 "type": "textbooks",
 "name": "Textbooks"
 },
 {
 "type": "discussion",
 "name": "Discussion"
 },
 {
 "type": "wiki",
 "name": "Wiki"
 },
 {
 "type": "progress",
 "name": "Progress"
 }
 ],
 "discussion_topics": {
 "一般": {
 "id": "course"
 }
 },
 "start": ISODate("2030-01-01T00:00:00Z"),
 "children": [
 [
 "chapter",
 "7270a053884041a2b2cc0e64065970f2"
 ]
 ]
 },
 "defaults": {

 },
 "edit_info": {
 "edited_by": NumberLong(9),
 "previous_version": ObjectId("5632e46950e3432ed9f51b07"),
 "original_usage_version": null,
 "original_usage": null,
 "edited_on": ISODate("2015-10-30T03:47:01.568Z"),
 "source_version": null,
 "update_version": ObjectId("5632e83550e3432edcf51b07")
 }
 },
 { # 默认存在overview block,它是课程介绍页面的内容
 "definition": ObjectId("5632e46950e3432ed9f51b0a"),
 "block_type": "about",
 "block_id": "overview",
 "fields": {
 "display_name": "overview"
 },
 "defaults": {

 },
 "edit_info": {
 "edited_by": NumberLong(9),
 "previous_version": null,
 "original_usage_version": null,
 "original_usage": null,
 "edited_on": ISODate("2015-10-30T03:30:49.558Z"),
 "source_version": null,
 "update_version": ObjectId("5632e46950e3432ed9f51b07")
 }
 }
 ],
 "root": [
 "course",
 "course"
 ]
}

XBlock Definitions存储具体的block,比如:

{
 "_id": ObjectId("5632e46950e3432ed9f51b06"),
 "fields": {
 "wiki_slug": "test10org.test10code.2015"
 },
 "edit_info": {
 "edited_on": ISODate("2015-10-30T03:30:49.380Z"),
 "edited_by": NumberLong(9),
 "original_version": ObjectId("5632e46950e3432ed9f51b06"),
 "previous_version": null
 },
 "block_type": "course",
 "schema_version": 1
}{
 "_id": ObjectId("5632e46950e3432ed9f51b0a"),
 "fields": {
 "data": "<section class=\"about\">\n <h2>About This Course</h2>\n <p>Include your long course description here. The long course description should contain 150-400 words.</p>\n\n <p>This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.</p>\n</section>\n\n<section class=\"prerequisites\">\n <h2>Requirements</h2>\n <p>Add information about the skills and knowledge students need to take this course.</p>\n</section>\n\n<section class=\"course-staff\">\n <h2>Course Staff</h2>\n <article class=\"teacher\">\n <div class=\"teacher-image\">\n <img src=\"/static/images/placeholder-faculty.png\" align=\"left\" style=\"margin:0 20 px 0\" alt=\"Course Staff Image #1\">\n </div>\n\n <h3>Staff Member #1</h3>\n <p>Biography of instructor/staff member #1</p>\n </article>\n\n <article class=\"teacher\">\n <div class=\"teacher-image\">\n <img src=\"/static/images/placeholder-faculty.png\" align=\"left\" style=\"margin:0 20 px 0\" alt=\"Course Staff Image #2\">\n </div>\n\n <h3>Staff Member #2</h3>\n <p>Biography of instructor/staff member #2</p>\n </article>\n</section>\n\n<section class=\"faq\">\n <section class=\"responses\">\n <h2>Frequently Asked Questions</h2>\n <article class=\"response\">\n <h3>Do I need to buy a textbook?</h3>\n <p>No, a free online version of Chemistry: Principles, Patterns, and Applications, First Edition by Bruce Averill and Patricia Eldredge will be available, though you can purchase a printed version (published by FlatWorld Knowledge) if you’d like.</p>\n </article>\n\n <article class=\"response\">\n <h3>Question #2</h3>\n <p>Your answer would be displayed here.</p>\n </article>\n </section>\n</section>\n"
 },
 "edit_info": {
 "edited_on": ISODate("2015-10-30T03:30:49.557Z"),
 "edited_by": NumberLong(9),
 "original_version": ObjectId("5632e46950e3432ed9f51b0a"),
 "previous_version": null
 },
 "block_type": "about",
 "schema_version": 1
}

总结一下:openedx在课程数据存储上是很弹性的,它通过多个分支来分别存储课程内容,在存储方式上每次修改都是产生一个ObjectID和对应的json文档数据,是新增数据而不是直接修改数据库中原有数据,这便于版本控制。另外,Xblock作为独立章节的内容存储单元便于复用。

此条目发表在 Open edX 分类目录。将固定链接加入收藏夹。

发表评论

要发表评论,您必须先登录