[英]how to read the data periodically from mongoDB in Python
I want to read the data from mongoDB in every 5 minutes in python. 我想在python中每5分钟从mongoDB中读取一次数据。 I am able to read the data in using pymongo.
我能够使用pymongo读取数据。 But, thats one time.
但是,那是一次。 I want to establish mongoDB connection in every 5 minutes and look for new documents.
我想每5分钟建立mongoDB连接并查找新文档。
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?
我可以让它休眠5分钟,然后再次与数据库建立连接吗? Please help..
请帮忙..
I think you're looking for a scheduler. 我认为您正在寻找调度程序。 I use
celery
for these kind of things, however it does more than this. 我将
celery
用于此类用途,但除此以外,它还具有更多用途。
have a look at http://www.celeryproject.org/ and also http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html 看看http://www.celeryproject.org/和http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.