From c5770668e06d76b7aa1ff8ba8bd86b413f1721e7 Mon Sep 17 00:00:00 2001 From: Michael Stephens Date: Wed, 30 Jun 2010 11:33:58 -0400 Subject: [PATCH] allow first argument of MongoDBEmitter to be a pymongo.database.Database instance --- saucebrush/emitters.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/saucebrush/emitters.py b/saucebrush/emitters.py index 554f2b0..aa3665c 100644 --- a/saucebrush/emitters.py +++ b/saucebrush/emitters.py @@ -183,10 +183,16 @@ class MongoDBEmitter(Emitter): """ def __init__(self, database, collection, host='localhost', port=27017, drop_collection=False, conn=None): super(MongoDBEmitter, self).__init__() - if not conn: - from pymongo.connection import Connection - conn = Connection(host, port) - db = conn[database] + + from pymongo.database import Database + if not isinstance(database, Database): + if not conn: + from pymongo.connection import Connection + conn = Connection(host, port) + db = conn[database] + else: + db = database + if drop_collection: db.drop_collection(collection) self.collection = db[collection]