V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Apr 5, 2017 · 2142 views
    This topic created in 3311 days ago, the information mentioned may be changed or developed.

    首先是代码:

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

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

    Supplement 1  ·  Apr 5, 2017
    解决了。谢谢提醒。
    2 replies    2017-04-05 14:21:57 +08:00
    AZLisme
        2
    AZLisme  
       Apr 5, 2017   ❤️ 1
    第一行代码你的$set 没有加引号, Python 懵逼
    另外 update 已经被 deprecated ,推荐使用 update_one() 或者 update_many()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1058 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 22:38 · PVG 06:38 · LAX 15:38 · JFK 18:38
    ♥ Do have faith in what you're doing.