Pymongo 中 update 的错误

2017-04-05 14:10:11 +08:00
 linkbg

首先是代码:

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

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

1484 次点击
所在节点    Python
2 条回复
imeee
2017-04-05 14:20:58 +08:00
AZLisme
2017-04-05 14:21:57 +08:00
第一行代码你的$set 没有加引号, Python 懵逼
另外 update 已经被 deprecated ,推荐使用 update_one() 或者 update_many()

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/352643

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX