V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
linkbg
V2EX  ›  Python

Pymongo 中 update 的错误

  •  
  •   linkbg · 2017-04-05 14:10:11 +08:00 · 1481 次点击
    这是一个创建于 2579 天前的主题,其中的信息可能已经有所发展或是发生改变。

    首先是代码:

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

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

    第 1 条附言  ·  2017-04-05 17:36:52 +08:00
    解决了。谢谢提醒。
    2 条回复    2017-04-05 14:21:57 +08:00
    imeee
        1
    imeee  
       2017-04-05 14:20:58 +08:00   ❤️ 1
    AZLisme
        2
    AZLisme  
       2017-04-05 14:21:57 +08:00   ❤️ 1
    第一行代码你的$set 没有加引号, Python 懵逼
    另外 update 已经被 deprecated ,推荐使用 update_one() 或者 update_many()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2907 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:30 · PVG 20:30 · LAX 05:30 · JFK 08:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.