search

Home  >  Q&A  >  body text

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'"

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

迷茫迷茫2875 days ago619

reply all(2)I'll reply

  • 大家讲道理

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

    In addition, update has been deprecated, it is recommended to use update_one() or update_many()
    https://docs.mongodb.com/gett...

    reply
    0
  • 黄舟

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

    The prompt is very clear. The DB.test.update method requires at least three parameters, and you only passed two parameters

    reply
    0
  • Cancelreply