Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2751

Deferred query EstimatedDocumentCount helper incorrect with filter

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 100.3.0
    • Component/s: None
    • Labels:
      None

      Description

      The tools-common type db.DeferredQuery has a method EstimatedDocumentCount, but estimated counts are only possible on full collections, not on queries with filters.

      As currently written, it will ignore the filter and return a full collection count, which is wrong.

      I suggest the following changes:

      • Run EstimatedDocumentCount on the underlying collection if the filter is nil or an empty BSON document
      • Run CountDocuments on the underlying collection otherwise
      • Consider renaming db.DeferredQuery.EstimatedDocumentCount to db.DeferredQuery.Count.

        Attachments

          Activity

            People

            Assignee:
            huan.li Huan Li
            Reporter:
            david.golden David Golden
            Reviewers:
            Evgeni Dobranov, Tim Fogarty
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: