首页 > 解决方案 > pymongo:如何用字典列表替换许多文档

问题描述

我是 pymongo 的新手,我不明白如何运行从 mysql 到 pymongo 的等价物

"REPLACE INTO XXXX (column1, column2, column3, column4, column5) VALUES" + results

我只是想向 collection.replace_many() 发送一个列表,但它不起作用。我跑

collection.replace_many(<list of dict>)

我收到了这个错误:

TypeError: 'Collection' object is not callable. If you meant to call the 'replace_many' method on a 'Collection' object it is failing because no such method exists.

我正在使用:pymongo.version:'3.11.2'

标签: pythonmongodbreplaceinsertpymongo

解决方案


MongoDB doesn't have a ReplaceMany; the equivalent to REPLACE INTO is UpdateMany (update_many() in pymongo) with Upsert set to True


推荐阅读