collection.count_documents() should accept same kwargs as collection.find()

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: 4.16.0
    • Component/s: Query Operations
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Problem

      `pymongo.collection.Collection.count_documents()` does not accept `min` and `max`, even though these kwargs can be passed to `pymongo.collection.Collection.find()` and can alter the document count. This makes `count_documents()` useless for certain queries.

      Definition of half-way done

      `pymongo.collection.Collection.count_documents()` accepts kwargs `min` and `max` and returns the correct number of documents.

      Definition of fully done

      `pymongo.collection.Collection.count_documents()` accepts all kwargs of `pymongo.collection.Collection.find()` and returns the correct document count when users write:
      ```
      find_kwargs = {...}
      with pymongo.MongoClient(host, port) as mongo:
          coll = mongo[database][collection]
          n_docs = coll.count_documents(**find_kwargs)
          with coll.find(**find_kwargs) as cursor:
              # do stuff    
      ```

      Idea for alternative, best solution

      `pymongo.collection.Collection.find()` itself should give access to the total number of matched documents. This improvement would make `pymongo.collection.Collection.count_documents()` redundant.

            Assignee:
            Unassigned
            Reporter:
            Dimitrios Tsevas
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: