allow first argument of MongoDBEmitter to be a pymongo.database.Database instance
This commit is contained in:
parent
559eb725e6
commit
c5770668e0
@ -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__()
|
||||||
|
|
||||||
|
from pymongo.database import Database
|
||||||
|
if not isinstance(database, Database):
|
||||||
if not conn:
|
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]
|
||||||
|
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]
|
||||||
|
Loading…
Reference in New Issue
Block a user