Last active
December 15, 2015 09:49
-
-
Save alejandrobernardis/5241307 to your computer and use it in GitHub Desktop.
MongoEngine, create and set all DB's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import settings | |
| from mongoengine import connect as mongodb_connect | |
| from mongoengine import register_connection | |
| from pymongo.database import Database | |
| _database_settings = dict( | |
| host=settings.DATABASE_HOST, | |
| port=settings.DATABASE_PORT, | |
| username=settings.DATABASE_USER, | |
| password=settings.DATABASE_PASS) | |
| dbcnx = mongodb_connect(settings.DATABASE_NAME, **_database_settings) | |
| _db = Database(dbcnx, 'admin') | |
| _db.authenticate(settings.DATABASE_USER, settings.DATABASE_PASS) | |
| for a in settings.DATABASE_MULTIPLE: | |
| # config | |
| _cfg = settings.DATABASE_MULTIPLE[a] | |
| # create | |
| _db = Database(dbcnx, _cfg.get('name')) | |
| _db.authenticate(settings.DATABASE_USER, settings.DATABASE_PASS) | |
| _db.add_user(_cfg.get('username'), _cfg.get('password')) | |
| # register | |
| register_connection(**_cfg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #: database (default) | |
| DATABASE_ORM = True | |
| DATABASE_NAME = 'admin' | |
| DATABASE_USER = 'admin' | |
| DATABASE_PASS = 'admin' | |
| DATABASE_HOST = '127.0.0.1' | |
| DATABASE_PORT = 27017 | |
| DATABASE_CONN = 100 # poll_size | |
| DATABASE_AREQ = True # auto_start_request | |
| DATABASE_UGLS = False # greenlets | |
| #: database async | |
| DATABASE_CACH = 10 | |
| #: database (others) | |
| DATABASE_MULTIPLE = dict( | |
| users=dict( | |
| alias='users-db', | |
| name='local-users', | |
| username='admin', | |
| password='admin', | |
| host='127.0.0.1', | |
| port=27017, | |
| max_pool_size=100, | |
| auto_start_request=True, | |
| use_greenlets=False | |
| ), | |
| events=dict( | |
| alias='events-db', | |
| name='local-events', | |
| username='admin', | |
| password='admin', | |
| host='127.0.0.1', | |
| port=27017, | |
| max_pool_size=100, | |
| auto_start_request=True, | |
| use_greenlets=False | |
| ), | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment