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

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

    XMLWordPrintable

    Details

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

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: