MongoEngine / MongoEngine/mongoengine

None of the switch_db or switch_collection support is thread-safe

Open
#2,685 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

As per this long standing issue: https://github.com/MongoEngine/mongoengine/issues/788

It seems the original intent of these switching mechanisms was to support archiving or similar use-cases.

However, more generally, I may just have a document model that I want to use against many different Mongo databases (all of which contain data for the same model) but all within the same Python process, and all concurrently (eg. if my application is a multi-user service). Ultimately, the name of the database to use for any given call into the system could even be completely dynamic, i.e. driven by user inputs to the system itself.

To support this, we need to use thread locals.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the switch_db and switch_collection mechanisms described here and review the long-standing issue #788 for context. The work is complete when concurrent use in one Python process can select different databases or collections without thread interference, including dynamically chosen databases.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.