簡體   English   中英

TypeError:“集合”對象不可調用(delete_one 出錯)

[英]TypeError: 'Collection' object is not callable (Error with delete_one)

這段代碼運行良好。 它訪問 Mongo 數據庫的集合,提取數據並刪除最舊的數據。 然而,從一周前開始,雖然我可以訪問數據、過濾和顯示它們,但我無法刪除它們,因為它告訴我delete_one不是“收集”的方法數據庫處於活動狀態(它使用 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)

有誰知道會發生什么? 這非常罕見,我在互聯網上找不到任何東西。 提前致謝。

使用它來代替“tweets_collection.delete_one({'created_at':fecha})”這個“tweets_collection.deleteOne({'created_at':fecha})”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM