Should I be re-initializing the connection on every insert?
class TwitterStream:
def __init__(self, timeout=False):
while True:
dump_data()
def dump_data:
##dump my data into mongodb
##should I be doing this every time??:
client=MongoClient()
mongo=MongoClient('localhost',27017)
db=mongo.test
db.insert('some stuff':'other stuff')
##dump data and close connection
#########################
Do I need to open the connection every time I write a record? Or can I leave a connection open assuming I'll be writing to the database 5 times per second with about 10kb each time?
If just one connection is enough, where should I define the variables which hold the connection (client
, mongo
, db
)?