推荐学习书目
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
wind3110991
V2EX  ›  Python

刚刚入 Tornado 坑,用 mongo 时,为何使用 pymongo 时无法使用 Connection 函数了?

  •  1
     
  •   wind3110991 · Apr 18, 2015 · 9571 views
    This topic created in 4047 days ago, the information mentioned may be changed or developed.
    >>> import pymongo
    >>> conn = pymongo.Connection("localhost",27017)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'Connection'
    难道pymongo3.0没有这个函数了?

    配置MongoDB正常,开了bin里的mongod和mongo环境

    pip装的 pymongo3.0
    头文件导入正常

    现在只能暂时用
    client = MongoClient("localhost",27017)
    代替,其他正常
    有没有人和我一样情况的?
    5 replies    2015-04-18 09:21:31 +08:00
    scys
        1
    scys  
       Apr 18, 2015   ❤️ 1
    为啥要用connection,是库没有Connection
    详细自己看看API https://api.mongodb.org/python/current/api/index.html
    wind3110991
        2
    wind3110991  
    OP
       Apr 18, 2015
    @scys Get!原来是最新没有Connection了 = =谢啦
    futursolo
        3
    futursolo  
       Apr 18, 2015
    Tornado 的话应该使用异步驱动程序Motor,而不是同步驱动程序PyMongo。

    https://motor.readthedocs.org/en/stable/

    使用Tornado的话,请牢记异步优先的准则。
    no13bus
        4
    no13bus  
       Apr 18, 2015
    @futursolo 说的很对,必须全部异步,不管何时何地,否则这条线上有一个环节是同步 那么你的过程就是阻塞的。到时候还不如用gevent+flask
    no13bus
        5
    no13bus  
       Apr 18, 2015
    当然 motor是基于pymongo的,只是写的时候前面要加个 yield.
    具体可以看我的开源:
    https://github.com/no13bus/ohmyrepo
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1589 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 16:23 · PVG 00:23 · LAX 09:23 · JFK 12:23
    ♥ Do have faith in what you're doing.