推荐学习书目
› 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 · Jul 31, 2018 · 6577 views
    This topic created in 2978 days ago, the information mentioned may be changed or developed.

    如何避免这个报错呢?

    def get_registered_user():
        users = collection_users.find({'regDate': regDate}).count()
        pprint.pprint("注册用户:" + str(users))
    
    4 replies  •  2018-07-31 17:38:00 +08:00
    thebigban
        1
    thebigban  
       Jul 31, 2018 via Android
    提示你使用 count_document,count 应该是老的方法了,换一个方法就好了
    Kakarrot
        2
    Kakarrot  
    OP
       Jul 31, 2018
    @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
       Jul 31, 2018
    ```
    def get_registered_user():
    users = collection_users.count_documents({'regDate': regDate})
    pprint.pprint("注册用户:" + str(users))
    ```
    datou
        4
    datou  
       Jul 31, 2018
    mongo 这些提示我从来不管的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   817 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:19 · PVG 05:19 · LAX 14:19 · JFK 17:19
    ♥ Do have faith in what you're doing.