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,8 +171,9 @@ class MongoDBEmitter(Emitter):
be inserted are required parameters. The host and port are optional, be inserted are required parameters. The host and port are optional,
defaulting to 'localhost' and 27017, repectively. 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__() super(MongoDBEmitter, self).__init__()
if not conn:
from pymongo.connection import Connection from pymongo.connection import Connection
conn = Connection(host, port) conn = Connection(host, port)
db = conn[database] db = conn[database]