问题
I have multiple databases with same collection names, document types, etc.
In source code at Github, documents use get_db method to choose the database to work on and in that method there is another call to get server connection. Both of these processes works with same parameter that called "alias".
Let's say that I have all my db connections defined with same server details and different databases, aliases. In that way, there will be multiple connections to same server. But it would be better if I could change database on a single connection. For example;
import pymongo
con = pymongo.connection(/* ... */)
def dummyDBSwitch(db):
global con
return con[db]
Is it possible to switch database before querying? Thanks.
回答1:
We add some methods to mongoengine source and fix this need this way, details: https://github.com/cool-shark/mongoengine
回答2:
This isnt currently possible but will be looked at in 0.8. Follow @metoikos's ticket: https://github.com/MongoEngine/mongoengine/issues/106
来源:https://stackoverflow.com/questions/12173469/how-to-switch-database-name-in-mongoengine