add conn init parameter so user can pass in an existing MongoDB connection

This commit is contained in:
Jeremy Carbaugh 2009-07-22 14:26:39 -04:00
parent 7f2619c7df
commit d8c3df88ab

View File

@ -171,10 +171,11 @@ class MongoDBEmitter(Emitter):
be inserted are required parameters. The host and port are optional,
defaulting to 'localhost' and 27017, repectively.
"""
def __init__(self, database, collection, host='localhost', port=27017, drop_collection=False):
def __init__(self, database, collection, host='localhost', port=27017, drop_collection=False, conn=None):
super(MongoDBEmitter, self).__init__()
from pymongo.connection import Connection
conn = Connection(host, port)
if not conn:
from pymongo.connection import Connection
conn = Connection(host, port)
db = conn[database]
if drop_collection:
db.drop_collection(collection)