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
wind3110991
V2EX  ›  Python

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

  •  1
     
  •   wind3110991 · 2015-04-18 01:43:19 +08:00 · 8724 次点击
    这是一个创建于 3268 天前的主题,其中的信息可能已经有所发展或是发生改变。
    >>> 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 条回复    2015-04-18 09:21:31 +08:00
    scys
        1
    scys  
       2015-04-18 01:56:02 +08:00   ❤️ 1
    为啥要用connection,是库没有Connection
    详细自己看看API https://api.mongodb.org/python/current/api/index.html
    wind3110991
        2
    wind3110991  
    OP
       2015-04-18 02:02:58 +08:00
    @scys Get!原来是最新没有Connection了 = =谢啦
    futursolo
        3
    futursolo  
       2015-04-18 08:55:55 +08:00
    Tornado 的话应该使用异步驱动程序Motor,而不是同步驱动程序PyMongo。

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

    使用Tornado的话,请牢记异步优先的准则。
    no13bus
        4
    no13bus  
       2015-04-18 09:20:16 +08:00
    @futursolo 说的很对,必须全部异步,不管何时何地,否则这条线上有一个环节是同步 那么你的过程就是阻塞的。到时候还不如用gevent+flask
    no13bus
        5
    no13bus  
       2015-04-18 09:21:31 +08:00
    当然 motor是基于pymongo的,只是写的时候前面要加个 yield.
    具体可以看我的开源:
    https://github.com/no13bus/ohmyrepo
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4940 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 01:12 · PVG 09:12 · LAX 18:12 · JFK 21:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.