How to prevent reinitialization of beanie for frequent database switching for queries #1072
xalien10
started this conversation in
Feature Request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
We're building a multi-tenant application based on FastAPI, MongoDB and Beanie. Within our services we need to switch between different databases so frequently. As part of these switching, we need to call
init_beanie()
every time we want to switch to a new database. We wanted to cache our saved clients during the initialization of beanie. But once we change the database, sessions started from that saved/cached client becomes invalid and raisingInvalidErrorOperation
.So, we were looking for a connection pool where beanie will try to look up if the settings are already initialised before and then it'll prevent from re-initializing it afterwards. We're expecting something ConnectionHandler in
tortoise-orm
.They're caching it locally and anytime the ORM is trying to get the pre-configured connection they can pull it by the alias name.
If there are some ways in beanie already present, so that we can save reinitializing the settings/configurations every time we want to switch the database, please enlighten us how to do it.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions