From 2b1c2d9d265bb2102e876966b2df45e500ae3668 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Thu, 2 Jul 2009 18:01:53 -0400 Subject: [PATCH] add ability to drop_collection on MongoDBEmitter --- saucebrush/emitters.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/saucebrush/emitters.py b/saucebrush/emitters.py index 266e09c..42ac005 100644 --- a/saucebrush/emitters.py +++ b/saucebrush/emitters.py @@ -171,11 +171,14 @@ 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): + def __init__(self, database, collection, host='localhost', port=27017, drop_collection=False): super(MongoDBEmitter, self).__init__() from pymongo.connection import Connection conn = Connection(host, port) - self.collection = conn[database][collection] + db = conn[database] + if drop_collection: + db.drop_collection(collection) + self.collection = db[collection] def emit_record(self, record): self.collection.insert(record)