openEDX课程数据的存储方式在官方文档中一节说明了其设计的核心思想,本文简单解释一下它的存储方式并通过查看数据库存储的内容来进一步了解它。
每个课程的数据都分三部分:
- 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# mongoMongoDB shell version: 2.6.11connecting to: test> use edxappswitched to db edxapp> show collectionsfs.chunksfs.filesmodulestore.active_versions # 即是Course Indexmodulestore.definitions # 即是XBlock Definitionsmodulestore.structures # 即是Course Structuressystem.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": "\n \n\nAbout This Course
\nInclude your long course description here. The long course description should contain 150-400 words.
\n\nThis is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.
\n\n \n\nRequirements
\nAdd information about the skills and knowledge students need to take this course.
\n\n \n\nCourse Staff
\n\n \n\n\n \n\n\nStaff Member #1
\nBiography of instructor/staff member #1
\n\n \n\n \n\n\nStaff Member #2
\nBiography of instructor/staff member #2
\n\n \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}\n \nFrequently Asked Questions
\n\n \n\nDo I need to buy a textbook?
\nNo, 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.
\n\n \nQuestion #2
\nYour answer would be displayed here.
\n
Mongodb操作记录:
1. 更新指定条件其中多少条记录:
db.modulestore.active_versions.find({org:"LzSH"}).limit(50).forEach(function(doc){ db.modulestore.active_versions.update({_id:doc._id},{$set:{org:"LzSouth"}})})