TypeError:'收集'对象不可呼应(delete_one错误)
这段代码运行得很好。它访问 Mongo 数据库的集合,提取数据并删除最旧的数据。然而,从一周前开始,虽然我可以访问数据,过滤和显示它们,但我无法删除它们,因为它告诉我 delete_one
不是“Collection”的方法数据库处于活动状态(它使用 docker-compose),正如我所说,您可以访问数据,并且每分钟都会添加新数据(在本例中为文档)。
with MongoClient(MONGODB_URI) as client: # MongoDB
db = client['twitter_raw']
tweets_collection = db['tweets_venezuela']
# number of documents in the collection
mydoc = tweets_collection.find().count()
print("The number of documents in collection : ", mydoc)
print(tweets_collection)
#tweets_collection.delete_one({'created_at':"2022-02-16 04:12:22"})
# print(tweets_collection.find_one())
for row in tweets_collection.find({}):
fecha = row["created_at"]
if(str(fecha) < "2022-02-17 04:12:22"):
tweets_collection.delete_one({'created_at':fecha})
else:
print(fecha)
有谁知道会发生什么?这是非常罕见的,我在互联网上找不到任何东西。 提前致谢。
This code was working perfectly. It accesses a collection of the Mongo database, extracts the data and deletes the oldest data. However, since a week ago, although I can access the data, filter and display them, I can not delete them because it tells me that delete_one
is not a method of "Collection" The database is active (It uses a docker-compose) and, as I said, is that you can access the data and every minute that passes new data (Documents in this case) are added.
with MongoClient(MONGODB_URI) as client: # MongoDB
db = client['twitter_raw']
tweets_collection = db['tweets_venezuela']
# number of documents in the collection
mydoc = tweets_collection.find().count()
print("The number of documents in collection : ", mydoc)
print(tweets_collection)
#tweets_collection.delete_one({'created_at':"2022-02-16 04:12:22"})
# print(tweets_collection.find_one())
for row in tweets_collection.find({}):
fecha = row["created_at"]
if(str(fecha) < "2022-02-17 04:12:22"):
tweets_collection.delete_one({'created_at':fecha})
else:
print(fecha)
Does anyone know what could be going on? It's quite rare and I can't find anything on the internet.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而是使用它“ tweets_collection.delete_one({'create_at':fecha})”此“ Tweets_collection.deleteone({'create_at':fecha':fecha})”
use it instead "tweets_collection.delete_one({'created_at':fecha})" this "tweets_collection.deleteOne({'created_at':fecha})"