简体   繁体   中英

how to switch database name in mongoengine

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.

我们向mongoengine源代码添加了一些方法,并通过这种方式解决了这一需求,详细信息: https : //github.com/cool-shark/mongoengine

This isnt currently possible but will be looked at in 0.8. Follow @metoikos's ticket: https://github.com/MongoEngine/mongoengine/issues/106

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM