Skip to content
Browse files

changes to allow

1) mongo AUTH if MONGO_USER is not an empty string
2) allow for keeping the DB and not deleting it on setup, this is important as AUTH
   requires the DB to be present with an user account created.
  • Loading branch information...
1 parent d0d864d commit b75f8d6b97a9c5b686961967d4d3f55646da05eb @kgorman kgorman committed Jul 9, 2012
Showing with 13 additions and 3 deletions.
  1. +5 −1 config.py
  2. +8 −2 mongo_database.py
View
6 config.py
@@ -23,7 +23,11 @@
# _mysql.connect; MONGO_FLAGS is used for pymongo.Connection.
MEMSQL_FLAGS = {'host': '127.0.0.1', 'port': 3306, 'user': 'root'}
MYSQL_FLAGS = {'host': '127.0.0.1', 'port': 3307, 'user': 'root'}
-MONGO_FLAGS = {}
+
+MONGO_FLAGS = {'host': '127.0.0.1', 'port': 27017}
+MONGO_USER = ''
+MONGO_PWD = ''
+MONGO_DROP_DATABASE = False
# The database class to use for the benchmark. Options are 'MemSqlDatabase',
# 'MySqlDatabase' and 'MongoDatabase'.
View
10 mongo_database.py
@@ -16,16 +16,22 @@
import pymongo
from base_database import BaseDatabase
-from config import MONGO_FLAGS
+from config import MONGO_FLAGS, MONGO_USER, MONGO_PWD, MONGO_DROP_DATABASE
class MongoDatabase(BaseDatabase):
'''An implementation of BaseDatabase using pymongo.'''
def __init__(self):
self.connection = pymongo.Connection(**MONGO_FLAGS)
self.db = self.connection.game
+ if MONGO_USER != '':
+ try:
+ self.db.authenticate(MONGO_USER,MONGO_PWD)
+ except Exception, e:
+ print e
def setup(self):
- self.connection.drop_database('game')
+ if MONGO_DROP_DATABASE:
+ self.connection.drop_database('game')
self.db.players.ensure_index([('id', pymongo.ASCENDING)])
self.db.games.ensure_index([('players', pymongo.ASCENDING)])
self.db.events.ensure_index([('user_id', pymongo.ASCENDING)])

0 comments on commit b75f8d6

Please sign in to comment.
Something went wrong with that request. Please try again.