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

DeprecationWarning: count is deprecated. Use Collection.count_documents instead.

  •  
  •   Kakarrot · 2018-07-31 16:44:17 +08:00 · 5422 次点击
    这是一个创建于 2094 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如何避免这个报错呢?

    def get_registered_user():
        users = collection_users.find({'regDate': regDate}).count()
        pprint.pprint("注册用户:" + str(users))
    
    4 条回复    2018-07-31 17:38:00 +08:00
    thebigban
        1
    thebigban  
       2018-07-31 16:54:20 +08:00 via Android
    提示你使用 count_document,count 应该是老的方法了,换一个方法就好了
    Kakarrot
        2
    Kakarrot  
    OP
       2018-07-31 16:56:59 +08:00
    @thebigban
    users = collection_users.find({'regDate': regDate}).count()
    改成
    users = collection_users.find({'regDate': regDate}).count_documents
    users = collection_users.find({'regDate': regDate}).count_documents()
    都不行啊
    Kakarrot
        3
    Kakarrot  
    OP
       2018-07-31 17:24:27 +08:00
    ```
    def get_registered_user():
    users = collection_users.count_documents({'regDate': regDate})
    pprint.pprint("注册用户:" + str(users))
    ```
    datou
        4
    datou  
       2018-07-31 17:38:00 +08:00
    mongo 这些提示我从来不管的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1189 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 473ms · UTC 18:22 · PVG 02:22 · LAX 11:22 · JFK 14:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.