Pruning the Open edX MongoDB structures collection

Open edX writes a new structures document on course saves, so the collection grows with every edit. This page explains why, what the pruning script removes, and how to back up before you run it.

On this page

Why the MongoDB structures collection grows on a busy Open edX platform

Every time a course team saves a change in Studio, the platform writes a new structures document to MongoDB, and the old one is not removed automatically. That is the core reason the structures collection keeps growing after repeated course edits, even when the course content itself changes very little. A course team that edits a unit, reorders a sequence or fixes a typo across several weeks can see its MongoDB storage climb steadily, and the platform will not reclaim that space on its own. The pruning script is the operator's control for this growth, and it is a task you own when you run Open edX yourself.

Open edX is built on Django and uses MongoDB as a required store for course structure, alongside MySQL for relational data. The edx-platform repository lists MongoDB 7.x among the components needed for development, so your self-hosted deployment must plan for it as a stateful service with its own sizing, access control and backups. Tutor is the official Docker-based distribution most teams use to run this stack, and it does not make the growth disappear. Who runs the script, when, and against which environment is a decision for your platform team, and it should be written into your operations runbook before the first large course cycle.

This page covers the mechanism behind the growth, what the pruning script removes and keeps, how to take a backup before running it, and what to confirm in your own environment. Confirm the exact MongoDB version your Tutor release deploys, the Open edX release you run, and whether your course volume is high enough for pruning to matter. Check the current script behavior in the edx-platform repository before you schedule any run, because the script's options and defaults are the details most likely to change between releases. The edx-platform GitHub repository is the natural place to start that check.

What the pruning script removes and what it keeps

Pruning targets structure versions that no active course branch points to any longer. Each time a course is edited and saved, the platform writes a new structure document, so superseded documents accumulate over time. A document becomes a candidate for removal only once nothing in the course's draft or published branches references it. The script should remove only what it can show is unreferenced.

  • Superseded drafts: structure versions replaced by later saves on the draft branch, once no branch points to them.
  • Published history no longer referenced: older published versions that the active published branch has moved past.
  • Structures of removed courses: documents for courses that no longer exist in the active course index, if your release includes this case.
  • Orphaned documents: entries left by interrupted writes or failed imports that no course branch references.

Before any production run, confirm with a test course which documents the script selects and why.

Back up MongoDB before running the pruning script

This sequence gives you a verified MongoDB backup, proven restorable on a scratch instance, and a checked course-loading result before any structures documents are removed. Each step closes with a check, so the prune only runs once you have evidence that a rollback is possible.

  1. Confirm the MongoDB backup method for your deployment

    Your platform team confirms how MongoDB is deployed in your environment, whether as a single Tutor-managed container, a self-managed replica set, or a managed service, and selects a backup method that matches it: a logical dump with a database tool, or a filesystem or volume snapshot taken while the database is quiesced. Confirm the exact MongoDB 7.x tooling and version with your own deployment owner and the MongoDB documentation before running anything. Done means a written note names the method, the tool version, the target storage location, and who holds the restore credentials.

  2. Take a backup and record its integrity

    The platform operator runs the chosen backup method against the database that holds the Open edX course structures, writing the output to storage outside the MongoDB host. Record the file or snapshot identifier, the time it was taken, the size, and a checksum or the tool's own completion report. Where your method allows it, also capture a copy of the Open edX configuration and secrets needed to reconnect the platform. Done means the backup artifact exists in a separate location and its checksum or completion report is saved with the change ticket.

  3. Verify the backup can be read

    Before relying on the backup, the operator confirms the artifact is complete and readable: the checksum matches the recorded value, and the dump or snapshot lists the expected databases and collections, including the structures collection. Store the verification output with the backup record. Done means the verification log shows no errors and the expected collections are present in the listing.

  4. Restore the backup to a scratch MongoDB instance

    The platform team restores the backup to a separate, isolated MongoDB 7.x instance that no learner or Studio author can reach, with its own credentials and no connection to production. This proves the backup is usable, not just present. Done means the restore completes without errors and the restored database reports a document count for the structures collection that you can compare with production.

  5. Check course loading on the restored copy

    Point a non-production Open edX stack, such as a staging Studio and LMS, at the restored database and open several representative courses in Studio, including large courses with many edits, then load the same courses in the LMS as an enrolled test learner. Check that course outlines, units and components render and that the course content opens without missing-block errors. Done means a short checklist records each course tested, the outcome, and any errors found, and the team signs off that the restored data serves correctly.

  6. Schedule the prune in a maintenance window

    The operations owner picks a maintenance window with the course authoring and support teams, announces it, and agrees who is on call and who can authorize a rollback to the verified backup. Confirm the pruning script's behavior and options against the version of Open edX you run before scheduling, and rehearse the command on the scratch copy first. Done means the window, the owners, the rollback decision point and the rehearsal result are recorded in the change ticket, and the backup from the earlier steps is referenced as the rollback source.

Pruning options and when each fits

This table compares the main ways to run the structures pruning script, from report-only passes to scheduled jobs and per-course cleanup. Read each row as a choice between speed, risk and review effort, and start from the most conservative option if this is your first run. Confirm the exact flags and modes in the script help for your Open edX release before you schedule anything.

ApproachWhen it fitsTrade-off to weighWhat to confirm first
Dry run or report-only firstFirst run on a production-sized database, or any time you are unsure what the script would removeNo change to the database, so the benefit is only information; someone must read the output and act on itWhether your release's script has a report or dry-run option and what its output lists
Scheduled pruning as a recurring jobSites with steady course edits where structures grow continuously and a predictable cleanup window existsEach run removes documents, so a bad rule or unexpected scope repeats on every run; needs logging and a backup step in the jobHow the job reports what it removed and where backups are stored between runs
One-off cleanup after a bulk importLarge course imports or mass re-saves that inserted many structure documents at onceHigher one-time review effort, and the team must confirm no active course depends on the removed versionsWhether the import's course keys can be targeted so the scope stays limited
Pruning per courseKnown courses with heavy edit history, or when you want to test the script on one course before a wider runSmaller blast radius and easier review, but many runs add operator time and need a list of courses to coverWhether the script accepts a course identifier and how it selects the versions to keep
Whole collection pruningPlatforms where most courses were edited heavily and a single maintenance window is acceptableLargest change set and longest review; a mistake affects every course, so a verified backup and a rollback plan are requiredExpected maintenance window size, restore test results and who signs off the run
Pruning during active editingRarely appropriate; only if your release documents it as safe with Studio in useConcurrent saves can race with deletion, so a quiet window is usually the safer choiceVendor or release guidance on whether Studio must be stopped during the run

Every save adds a structures document, so pruning runs only after a verified backup

The path starts when an author saves in Studio, which sends the change through the CMS and the modulestore. The modulestore writes a new document to the MongoDB structures collection on each save, so the collection grows with every edit. Before the pruning script runs, take a backup you have tested. After pruning, check the course in Studio and in the LMS. If either check fails, restore from that backup and do not treat the prune as finished.

The save path, the growth it causes, and the backup, prune, check and restore sequence.

Setting up a safe pruning routine on your platform

This sequence turns one-off pruning into a routine you can repeat: each step confirms what is stored, what may be removed, and how to recover if a run goes wrong. The result is a documented schedule that course teams and operators both understand.

  1. Inventory the MongoDB deployment and collection size

    The platform operator records how MongoDB is deployed (single instance, replica set or managed service), which Open edX databases it hosts, and the current size of the structures collection and its growth rate over recent weeks. Confirm the MongoDB version against the platform's documented requirements, since the edx-platform repository lists MongoDB 7.x for development. The step is done when you have a written baseline with collection size, total database size and free disk space, so later runs can be compared against it.

  2. Agree the retention and rollback policy

    The platform owner and course teams agree how long superseded course structures are kept and who may request a restore of a specific course. Ask course teams which edits they need to revert, such as a broken unit published the day before a cohort starts. The step is done when the policy is written down with an owner, a retention rule, and a named contact for restore requests, and when course teams have acknowledged it in writing.

  3. Set and test backup and restore

    Take a full MongoDB backup before any pruning run, and confirm the backup method suits your deployment, whether a logical dump, a filesystem snapshot or a managed-service backup. Restore that backup into a separate environment and check that the courses open in Studio and the LMS. The step is done when a restore has been completed and checked on a copy, and the restore time has been recorded so the rollback plan is based on a measured result rather than an assumption.

  4. Run the script on a staging copy built with Tutor

    Build a staging environment with Tutor, load a recent copy of the production MongoDB data, and run the structures pruning script in dry-run mode if the version you run provides one. Review which documents would be removed, and check that the active version of every course still loads and that a sample of recent edits remains intact. The step is done when the dry run output has been reviewed by the operator and at least one course team has confirmed their courses look correct on staging.

  5. Review the staging results and approve the change

    The operator and the platform owner compare the staging results with the baseline and the retention policy. They confirm the expected reduction in collection size, the disk space freed, and that no active course structure is in the removal set. Record any exceptions and decide whether to change the policy before production. The step is done when the approval is recorded with the date, the person who signed off, and the backup identifier that would be used for rollback.

  6. Run in production during a planned window

    Schedule the production run in a maintenance window agreed with course teams, take a fresh backup immediately before the run, and announce the window to learners and staff. Execute the script as approved on staging, capture its output, and keep the backup available until the check in the next step passes. The step is done when the run has completed without errors, the output is saved with the change record, and the fresh backup is confirmed as restorable.

  7. Monitor the platform after the run

    Verify that Studio saves, course loads and publishing work for a sample of courses, and watch error logs and MongoDB storage metrics for several days. Compare the collection size with the baseline to confirm growth has slowed. The step is done when the operator has signed off that the platform is stable and that no course team has reported a missing structure or failed revert.

  8. Repeat the routine on a schedule

    Set a recurring schedule for the inventory, backup test, staging run and production run, and assign an owner for each cycle. Update the retention policy when course volume or team requests change, and record each cycle in the same change log. The step is done when the schedule exists in your operations calendar, each cycle has a documented owner, and the next run date is confirmed with the course teams involved.

Security and access controls for pruning jobs

A pruning run deletes historical structure documents from MongoDB, so the account, backups, logs and credentials around it deserve the same review as any production data change. The cards below cover who can run the script, how backup copies are protected, and where the credentials live.

Least-privilege MongoDB account

Run pruning under a dedicated MongoDB user that holds only the rights the script needs on the edxapp database, rather than the admin or root account used for installation. Confirm the role grants with your MongoDB administrator before the first run, and remove the account once the work is finished. A separate account also makes it clear in the database logs which actions came from pruning and which came from the platform itself. Keep the account out of shared admin tooling.

Encrypted backup storage

Take the backup of the structures collection before pruning and encrypt it at rest, in the location your data protection policy already covers. Store it outside the MongoDB host so a failed run or a lost server does not take the restore point with it. Ask your storage team how keys are managed and who can read the bucket or volume. Test that a restore from the backup actually works before you rely on it.

Access to course content backups

Structure documents hold course content, so a backup copy is as sensitive as the course itself and can include unpublished material and learner-facing text. Limit read access to the small group that performs restores, and log each access. Set a retention period for the backup that matches how long you need the rollback option, then delete the copy on schedule. Confirm whether any course content in your catalog is under contractual or licensing limits that restrict who may hold a copy.

Audit trail for pruning runs

Record who started each pruning run, when it started and finished, the host it ran from, and the backup identifier it depended on. Keep the record in a system the pruning operators cannot edit, such as your central log platform or a ticketing change record. The trail answers questions after an incident and supports change reviews in an audit. Ask your team whether the script output alone is enough, or whether you need a separate change ticket for each run.

Credentials in Tutor configuration

MongoDB passwords used by the platform and by the pruning job should not sit in plain text in config.yml or in files committed to Git. Tutor reads its settings from a configuration directory and environment, so check which values end up in generated files and which are stored in the environment of the running containers. Use your secrets manager or the environment of the deployment runner for the pruning credential, rotate it after each planned job if your policy requires it, and confirm the rotation with the team that owns the MongoDB cluster.

Tutor docs

Questions teams ask before pruning MongoDB structures

Can we prune the Open edX MongoDB structures collection without an outside partner?

Yes, a team that already runs its Open edX platform and its MongoDB instance can run the pruning script itself, provided it has someone who can read the script's options, take and verify a backup, and restore it in a non-production copy. The harder question is whether that team has done it before on a platform with live course edits. Pruning deletes data, so the work is less about typing the command and more about confirming the backup, the target environment and the rollback path. A partner adds value mainly when the team lacks MongoDB operations experience or when the prune must be rehearsed against a production-sized copy on a deadline. Confirm your skills against the steps on this page before deciding.

What drives the effort and cost of a MongoDB pruning project?

The main drivers are the size and growth rate of the structures collection, how many courses are edited often, how many environments the team must prepare, and how much of the backup and restore process is already documented and tested. Costs fall into two groups. One-time costs include the initial assessment, the dry run in a copy, the backup and restore rehearsal, and documenting the runbook. Recurring costs include scheduled pruning, monitoring of database growth and periodic restore tests. When requesting a quote, ask for the written scope, which environments are included, who performs the restore test, and what the handover includes. DeployOpen does not publish prices, and a quote follows from the written scope.

How long does a pruning run and restore test take?

It depends on the size of the structures collection, the hardware and network of the MongoDB deployment, the storage speed of the backup target, and how many courses are included in the run. A small test instance will behave very differently from a production cluster with years of course edits. Because no reliable figure applies across environments, measure the duration on a copy of your own data. Time the backup, the prune and the restore separately, and record the document counts before and after. Ask any partner to base its schedule on a measured run in your environment rather than a generic estimate.

What must our team provide before a pruning project starts?

The team needs to provide access to a non-production copy of the platform and its MongoDB data, current backup procedures, a list of the courses and environments in scope, and the people who can approve the destructive step. Engineers should be able to run the Open edX and MongoDB commands in that environment and confirm which Tutor version and Open edX release are installed. Operations should share the maintenance window rules and the monitoring already in place. A named owner for backup verification and for signing off the production run keeps the work moving and prevents an unreviewed delete.

Is a dry run of the pruning script possible before we touch production?

A dry run is the right first step and should happen on a restored copy of production data, not on the live database. Start by taking a backup, restoring it to a separate MongoDB instance, and running the pruning script there with the same options you plan to use in production. Compare the collection size and document counts before and after, check that the courses still load in Studio and the LMS, and confirm that a published course can still be edited. Record the commands and the results so the production run repeats exactly what was tested. Confirm the script's exact options and behavior against the Open edX and Tutor documentation for your release before you start.

How does pruning the structures collection relate to scaling work?

Pruning and scaling solve different problems. Scaling adds web workers, Celery workers, database capacity, caching and replicas so the platform serves more learners. Pruning controls how fast the structures collection grows, because every course save inserts a new document, and that growth affects storage use and database performance over time. A platform that is scaled out but never pruned will keep accumulating structure documents, while a pruned platform may still be too small for a large launch. Plan pruning as a maintenance control that runs alongside capacity work, and check the database growth before a large enrollment event, as covered in the scaling guidance for this platform.

Can we restore the database if a pruning run removes something we need?

Yes, but only if the backup was taken and verified before the run and the restore has been rehearsed. A backup that has never been restored is an assumption, not a recovery plan. Before the production run, confirm that the backup completes, that it contains the structures collection, and that it restores to a clean MongoDB instance running the same version. Test that the restored platform starts and that the affected courses open in Studio. Keep the backup until the team has verified the courses after the prune. Ask any partner to show the restore test results as part of the handover.

How DeployOpen works on this

DeployOpen treats MongoDB structures pruning as a bounded piece of Open edX operations work inside infrastructure you control. We start from your current collection size, your course edit patterns and your backup position, then agree the work in writing before anything runs against production.

How we scope

  • Measure the structures collection size and growth against your course edit history and authoring activity.
  • Confirm which Open edX release and Tutor version your deployment runs before choosing the pruning approach.
  • Write the scope with backup verification, a rehearsal environment and a rollback position as named deliverables.

How we build

  • Rehearse the pruning script against a restored copy of your MongoDB data, never against production first.
  • Document which structures are removed, which are kept and how each decision was verified in your environment.
  • Set a scheduled pruning routine with logging so the collection stays bounded after the one-off cleanup.

How we hand over

  • Deliver a runbook covering pre-run backups, the exact commands, expected output and the restore procedure.
  • Walk your platform and database team through the run, the monitoring to watch and the escalation path.
  • Record the configuration, schedule and verification results so your own team can repeat the process later.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers when your platform changes.
  • Revisit the pruning routine during each Open edX upgrade so script behavior matches the new release.
  • Confirm with us whether a retainer covers collection growth reviews, backup restore tests and follow-up runs.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.