Skip to content

Remove mongodb backend#274

Merged
taimoor-ahmed-1 merged 9 commits intoopenedx:masterfrom
salman2013:salman/remove-mongodb-backend
Apr 28, 2026
Merged

Remove mongodb backend#274
taimoor-ahmed-1 merged 9 commits intoopenedx:masterfrom
salman2013:salman/remove-mongodb-backend

Conversation

@salman2013
Copy link
Copy Markdown
Contributor

@salman2013 salman2013 commented Apr 21, 2026

Summary

Remove the MongoDB backend from the openedx/forum service entirely. MySQL is now the only supported backend. All data migration tooling (MongoDB
→ MySQL commands, helpers, and tests) is preserved so operators can still migrate existing MongoDB data before fully decommissioning their
MongoDB deployment.


Motivation

openedx/public-engineering#424


What Was Removed

MongoDB backend package (forum/backends/mongodb/) — deleted entirely:

  • api.py — MongoBackend class
  • base_model.py — MongoBaseModel with MongoDB connection handling
  • comments.py, threads.py, contents.py, subscriptions.py, users.py — MongoDB collection models

Backend routing logic (forum/backend.py) — simplified from conditional flag-based routing to always returning MySQLBackend:

Waffle flag (forum/toggles.py) — deleted. ENABLE_MYSQL_BACKEND CourseWaffleFlag and enable_mysql_backend_for_course() are no longer needed since
MySQL is always used.

MongoDB index creation command (forum/management/commands/forum_create_mongodb_indexes.py) — deleted. Only relevant when running MongoDB.

MongoDB-specific Elasticsearch import path (forum/search/es.py):

  • Removed _import_to_es_from_mongo() method
  • Removed get_index_model_rel() method (returned MongoDB model instance)
  • Removed MongoDB model imports from forum.backends.mongodb
  • models property and rebuild_indices()/catchup_indices() now use MySQL models only

MongoDB-specific API routing (forum/api/threads.py, forum/api/comments.py):

  • get_course_id_by_thread() and get_course_id_by_comment() no longer fall back to MongoDB search; MySQL-only

MongoDB backend tests (tests/test_backends/test_mongodb/) — deleted entirely

MongoDB-specific thread view tests (tests/test_views/test_threads.py):

E2E docker-compose (tests/e2e/docker-compose.yml) — removed mongodb service block

Test fixtures (tests/conftest.py):

  • Removed patch_default_mongo_database autouse fixture
  • Removed parametrized patched_get_backend (previously ran all tests against both backends)
  • Removed patched_mongo_backend autouse fixture
  • Simplified patched_get_backend to return MySQLBackend directly

What Was Kept (Intentionally)

Migration commands (operators still need these to migrate existing MongoDB data):

  • forum/management/commands/forum_migrate_course_from_mongodb_to_mysql.py
  • forum/management/commands/forum_delete_course_from_mongodb.py
  • forum/migration_helpers.py — all migration logic intact

MongoDB connectivity (needed by migration commands):

  • forum/mongo.py — get_database() function
  • pymongo in requirements/base.in
  • mongomock in requirements/test.in
  • FORUM_MONGODB_DATABASE and FORUM_MONGODB_CLIENT_PARAMETERS settings

MongoContent MySQL model (forum/backends/mysql/models.py) — tracks MongoDB ObjectId → MySQL PK mappings used during migration; the corresponding
MongoContentAdmin in forum/admin.py is also kept

Migration tests (tests/test_management/test_commands/test_migration_commands.py) — all kept; only removed the patch_enable_mysql_backend fixture
that mocked the now-deleted enable_mysql_backend_for_course()


Key Code Changes

forum/search/es.py

  • models property returns mysql_model_indices (was mongo_model_indices)
  • mysql_models property kept unchanged
  • rebuild_indices() uses get_mysql_model_from_index_name() (previously called get_index_model_rel())
  • No method renames; only MongoDB-specific methods removed

forum/migration_helpers.py

  • Removed only enable_mysql_backend_for_course() function (sole dependency on deleted toggles.py)
  • All migrate_users, migrate_content, migrate_read_states, and related helpers untouched

forum/management/commands/forum_migrate_course_from_mongodb_to_mysql.py

  • Removed --no-toggle / -T argument
  • Removed enable_mysql_backend_for_course(course_id) call
  • Core migration loop unchanged

Testing Impact

  • All existing MySQL backend tests pass unchanged
  • Migration command tests pass unchanged
  • E2E tests pass unchanged
  • MongoDB backend tests deleted (no longer applicable)

Ticket:
openedx/public-engineering#502

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Apr 21, 2026
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Apr 21, 2026

Thanks for the pull request, @salman2013!

This repository is currently maintained by @openedx/wg-maintainers-forums.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Apr 21, 2026
@salman2013 salman2013 changed the title chore: remove mongodb backend Remove mongodb backend Apr 21, 2026
@salman2013 salman2013 added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Apr 22, 2026
Copy link
Copy Markdown
Contributor

@taimoor-ahmed-1 taimoor-ahmed-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good.

However, I would also suggest to drop the ENABLE_MYSQL_BACKEND waffle flag too in this PR.

@salman2013 salman2013 requested a review from ormsbee April 22, 2026 10:40
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Apr 22, 2026
@salman2013 salman2013 marked this pull request as ready for review April 23, 2026 06:11
@salman2013
Copy link
Copy Markdown
Contributor Author

@taimoor-ahmed-1 PR is available for review. Thanks

@taimoor-ahmed-1
Copy link
Copy Markdown
Contributor

Code changes look good. Can you also update README to remove all references to mongo backend and toggle.
Also, please bump up the version in the same PR.

Copy link
Copy Markdown
Contributor

@taimoor-ahmed-1 taimoor-ahmed-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@taimoor-ahmed-1 taimoor-ahmed-1 merged commit 3be8beb into openedx:master Apr 28, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in Contributions Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). create-sandbox open-craft-grove should create a sandbox environment from this PR open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants