首页  >  问答  >  正文

python - Pymongo 中 update 的错误

首先是代码:

DB.test.update(query={'host': ip, 'port': port}, update={$set: {'http': 'test'}})

这个代码会报这样的错误:

TypeError: 'update() takes at least 3 arguments (1 given)

在这个之前我使用了最最简单的:

DB.test.update({'host': ip, 'port': port}, {"$set": {'http': 'test'}})

报的错误:

TypeError: "unhashable type: 'dict'"

我一脸的蒙蔽阿。什么情况。 这个是问题是在这个主题的一个简单解决方案。这情况怎么解决?

迷茫迷茫2741 天前551

全部回复(2)我来回复

  • 大家讲道理

    大家讲道理2017-04-18 10:33:54

    另外 update 已经被 deprecated ,推荐使用 update_one() 或者 update_many()
    https://docs.mongodb.com/gett...

    回复
    0
  • 黄舟

    黄舟2017-04-18 10:33:54

    提示给的很清楚啊,DB.test.update这个方法至少需要三个参数,你只传了两个参数

    回复
    0
  • 取消回复