收集'对象不可呼应。如果您打算调用更新'收集'对象失败了,因为不存在这样的方法

发布于 2025-01-27 10:02:43 字数 471 浏览 2 评论 0原文

我试图使用Pymongo将记录保存到Mongo DB中。如果存在或插入一个记录,我有脚本可以更新集合。该片段在交互式运行时起作用,但是当我尝试从Docker做同样的操作时,脚本会失败,而错误 - 集合的对象是无法callable的。如果您打算在“集合”对象上调用“更新”方法,则由于不存在这种方法而失败。

    def store_failed_cbsd(id,data,collection_name,mongo_client):      
      output_content = {'_id' : id,'data' : [data]}   
      key = {'_id': id}    
      mongo_client.get_database()[collection_name].update(key,    
      output_content, upsert=True)

Pymongo版本-4.1.1 我想念什么?

I am trying to save a record into mongo db using pymongo. I have the script to update the collection if it exists or insert one record. This snippet works when run interactively, but when I try to do the same from docker, the script fails with the error - Collection' object is not callable. If you meant to call the 'update' method on a 'Collection' object it is failing because no such method exists.

    def store_failed_cbsd(id,data,collection_name,mongo_client):      
      output_content = {'_id' : id,'data' : [data]}   
      key = {'_id': id}    
      mongo_client.get_database()[collection_name].update(key,    
      output_content, upsert=True)

PyMongo Version - 4.1.1
What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

迷迭香的记忆 2025-02-03 10:02:43

update()对pymongo 4进行了弃用。使用update_many()update_one()而不是。

https://pymongo.readthedocs.io /en/stable/migrate-to-pymongo4.html#Collection-update-is-bemped

update() was deprecated for pymongo 4. Use update_many() or update_one() instead.

https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#collection-update-is-removed

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