Split Modulestore (Draft Versioning Modulestore)

Split Mongo supports an arbitrary number of branches, though only "draft" and "published" are currently used. Course version history is preserved as edits are made, allowing rollback to a previous course version. Course locators for Split courses are the new style supported by opaque_keys. For example, here's a serialized Split course locator:


References - Old and New








Course Format in MongoDB

There are three Split Mongo collections in MongoDB:

  • modulestore.active_versions
  • modulestore.structures
  • modulestore.definitions


  • Each course has a single active_versions document.
    • That document points to both a draft and published structures _id.


  • The entire course structure is stored in a single structures document.
    • Each time a structure changes, a new structure is created by cloning and changing the previous structure.
  • The version of a course branch is the _id of the course branch's most recent structures document.
  • Each course has a current draft structure and a current published structure.


  • A course structure does not contain the course content. The content is kept in the definitions collection.

The Code

Query Patterns

To retrieve the entire published course structure, the modulestore queries a single document from active_versions and another single document from structures (by _id).

Other Relevant Pages/Slides/Docs/Code

How to Recover from a Broken Split Course

A project was started to assist in determining information about the history of a Split course - and to rollback a course to an earlier version. It's here:


How To Find the Size of All Active Structures

Issue this command at the MongoDB command line of the replica DB:

    function(obj) {
        var published_id = obj["versions"]["published-branch"];
        struct_obj = db.modulestore.structures.findOne(published_id);
        var curr = Object.bsonsize(struct_obj);
        print(curr + " :: " + obj["org"] + "/" + obj["course"] + "/" + obj["run"]);

How To Walk Structure History Backwards From the Current Active Version 

var course_id = { "org": "HarvardX", "course": "SPU27x", "run": "2015_Q2"};
course_idx = db.modulestore.active_versions.findOne(course_id);
print("Course Index:")

var pub_struct_id = course_idx["versions"]["draft-branch"];

/* Walk the draft structure version tree backwards. */
var curr_struct = db.modulestore.structures.findOne( { "_id": pub_struct_id }, {_id: 1, edited_on: 1, previous_version: 1} );
print("Current draft structure: " + curr_struct._id);
print("Edited on: " + curr_struct.edited_on);

var generation = 1;
while ( curr_struct != null ) {
    curr_struct = db.modulestore.structures.findOne( { "_id": curr_struct.previous_version }, {_id: 1, edited_on: 1, previous_version: 1} );
    print("Previous: " + curr_struct._id + " - Edited on: " + curr_struct.edited_on + " - generation: " + generation);