Created
September 9, 2015 08:05
-
-
Save leafsummer/9fa4d72b4463aedc3804 to your computer and use it in GitHub Desktop.
A class of custom mongo client
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 pymongo | |
| import conf as ncconf | |
| class MongoDB(object): | |
| def __init__(self): | |
| # self.conn = pymongo.Connection(ncconf.MONGO_SERVER, ncconf.MONGO_PORT) | |
| # self.mongo_db = pymongo.database.Database(self.conn, ncconf.MONGO_DB) | |
| self.conn = pymongo.MongoClient(host=ncconf.MONGO_SERVER, port=ncconf.MONGO_PORT, max_pool_size=50, socketTimeoutMS=60000) | |
| self.mongo_db = self.conn[ncconf.MONGO_DB] | |
| def __enter__(self): | |
| return self.mongo_db | |
| def __exit__(self): | |
| self.conn.disconnect() | |
| mongodb = MongoDB().mongo_db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment