TypeError:'收集'对象不可呼应(delete_one错误)

发布于 2025-01-19 15:04:01 字数 927 浏览 5 评论 0原文

这段代码运行得很好。它访问 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风尘浪孓 2025-01-26 15:04:01

而是使用它“ 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})"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文