How to get the length of a cursor from mongodb using python?

后端 未结 6 1482
南笙
南笙 2021-02-19 01:49

I\'m looking for a feasible way to get the length of cursor got from MongoDB.

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 02:17

    cursor.count()

    Counts the number of documents referenced by a cursor. Append the count() method to a find() query to return the number of matching documents. The operation does not perform the query but instead counts the results that would be returned by the query.

    db.collection.find().count()
    

    https://docs.mongodb.com/manual/reference/method/db.collection.count/

提交回复
热议问题