Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-35202

Parsing of count() commands with limit modifiers is counter-intuitive

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.5
    • Component/s: Querying
    • Labels:
      None

      MyColl has 20 documents, as count() and find().count() confirm, but adding limit(10) still returns 20:

        db.MyColl.count()
          20
      
        db.MyColl.find().count()
          20
      
        db.MyColl.find().limit(10).count()
          20
      

      This is the correct syntax as per our documentation for cursor.count() - the default behaviour when applySkipLimit is not set to true is to ignore any skip(n) and limit(m) methods.

      However, it is counter-intuitive for a user to have included the limit(10) but to also want it to be ignored. Note further that itcount() behaves differently:

        db.MyColl.find().limit(10).itcount()
          10
      

      Conclusion: the default value for applySkipLimit should be true.

            Assignee:
            asya.kamsky@mongodb.com Asya Kamsky
            Reporter:
            william.byrne@mongodb.com William Byrne III
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: