allow first argument of MongoDBEmitter to be a pymongo.database.Database instance

This commit is contained in:
Michael Stephens 2010-06-30 11:33:58 -04:00
parent 559eb725e6
commit c5770668e0

View File

@ -183,10 +183,16 @@ class MongoDBEmitter(Emitter):
""" """
def __init__(self, database, collection, host='localhost', port=27017, drop_collection=False, conn=None): def __init__(self, database, collection, host='localhost', port=27017, drop_collection=False, conn=None):
super(MongoDBEmitter, self).__init__() super(MongoDBEmitter, self).__init__()
if not conn:
from pymongo.connection import Connection from pymongo.database import Database
conn = Connection(host, port) if not isinstance(database, Database):
db = conn[database] if not conn:
from pymongo.connection import Connection
conn = Connection(host, port)
db = conn[database]
else:
db = database
if drop_collection: if drop_collection:
db.drop_collection(collection) db.drop_collection(collection)
self.collection = db[collection] self.collection = db[collection]