2

I want to read the data from mongoDB in every 5 minutes in python. I am able to read the data in using pymongo. But, thats one time. I want to establish mongoDB connection in every 5 minutes and look for new documents.

client = MongoClient('localhost', 27017)
db = client.test_insert
collection = db.dataset

for docs in db.dataset.find():
    print docs

But I have to manually do it. Can I make it sleep for 5 minutes and then again establish a connection with the database? Please help..

Neil
  • 7,937
  • 22
  • 87
  • 145

1 Answers1

0

I think you're looking for a scheduler. I use celery for these kind of things, however it does more than this.

have a look at http://www.celeryproject.org/ and also http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html

mehdy
  • 3,174
  • 4
  • 23
  • 44