MongoEngine / MongoEngine/mongoengine

dynamically switching db (when dbs are created dynamically, so cannot use aliases)

Open
#1,986 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

i will try to describe my usecase here:
i am using a multi tenant db model in which each client has their own database( due to very specific business use case). suppose i have to get the users details for a client x that has its own db named x,
these are the steps i need to execute to get the data:

  • connect to admin db & get admin details
  • connect to x db & get list of users
  • connect to cc db & insert some data

all of the above operations are to be executed in a single request to get the required results.

basically i need to map a Document class to multiple dbs which are created dynamically(as clients register) so i cannot hard code this in the document definition.

i guess the default behavior of mongoengine is to bind each Document to a specific database as soon as the code defining the document is executed, but we somehow need to bind documents to a db's dynamically.

other issues that are almost related:
#1610
any specific architectural reason to bind a document to a database at the first execution of document?

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 by reading the document-to-database binding behavior described in the issue and comparing the use case with related issue #1610. Trace how a Document is associated with a database during definition, then establish the scope and tests needed for switching among dynamically named databases within one request; no files or existing tests are identified here.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.