
[英]How to query and update entries in MongoDB (Pymongo) effectively?
[英]How to look up the entries added to a table in last 5 seconds using Pymongo in python for mongodb
我需要查找添加到我的mongodb集合中的条目,这些条目是在过去10秒内创建或添加的。
目前我没有时间戳作为我已插入集合的文档的一部分。 通过阅读谷歌的东西,我知道我可以使用hte对象id以某种方式做到这一点,但我不明白我该怎么做。
你可以尝试:
from datetime import datetime
from bson.objectid import ObjectId
newdate = datetime.utcnow() + timedelta(seconds=-10)
dummy_id = ObjectId.from_datetime(newdate)
result = collection.find( { "_id": { "$gt": dummy_id } } )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.