Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Connecting to and switching multiple databases #64

Open
mgmonteleone opened this issue Mar 7, 2015 · 2 comments
Open

Connecting to and switching multiple databases #64

mgmonteleone opened this issue Mar 7, 2015 · 2 comments

Comments

@mgmonteleone
Copy link

Trying to implement a reporting API for multiple mongo databases with the same structure using mongorest...

Have tried to implement this using the mongoengine connect mechanism:

for mongoconfig in configmongos:
    print "Connecting: "+mongoconfig["name"]
    db.connect(
        name = mongoconfig["name"],
        host = mongoconfig["host"],
        port = mongoconfig["port"],
        db = mongoconfig["database"]
    )

and then using a variable in my document class:
class Products(db.Document):
productName = db.StringField()
businessUnit = db.StringField()
brand = db.StringField()
subBrand = db.StringField()
franchise = db.StringField()
category = db.StringField()
subCategory = db.StringField()

   meta = {'collection': 'products',"db_alias": selectedInstance}

But it seams that the db alias is always "default"

Any way to implement this?

@wojcikstefan
Copy link
Member

Hi, I think MongoEngine can only connect to one database at a time. You can open a ticket with them at https://github.com/MongoEngine/mongoengine.

@mgmonteleone
Copy link
Author

MongoEngine has the ability to connect to multiple databases, and then switch that database using an alias (see above), the issue is that the MongoRest always registers the connection as "default" alias. I will take a look at the code to see where this is being done, and perhaps I can come up with a patch to have MongoRest support multiple aliases....

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants