MongoEngine/mongoengine

None of the switch_db or switch_collection support is thread-safe

jessemcl-flwls opened this issue · 0 comments

As per this long standing issue: #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.