count with limit 0 fails on a view but works on a collection

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: 8.2.4, 7.0.31, 8.2.6, 8.2.12
    • Component/s: None
    • None
    • Query Optimization
    • ALL
    • Hide
      docker run -d --name repro mongo:8.2.12
      
      # wait for startup, then:
      docker exec repro mongosh --quiet test --eval '
        db.c.insertMany([{}, {}, {}, {}, {}]);
        db.createCollection("v", {viewOn: "c", pipeline: []});
        print("collection: " + db.runCommand({count: "c", limit: 0}).n);
        try { print("view: " + db.runCommand({count: "v", limit: 0}).n); }
        catch (e) { print("view: error " + e.code + ", " + e.errmsg); }
        print("view limit -1: " + db.runCommand({count: "v", limit: -1}).n);
      '
      
      collection: 5
      view: error 15958, the limit must be positive
      view limit -1: 1
      
      Show
      docker run -d --name repro mongo:8.2.12 # wait for startup, then: docker exec repro mongosh --quiet test --eval ' db.c.insertMany([{}, {}, {}, {}, {}]); db.createCollection("v", {viewOn: "c", pipeline: []}); print("collection: " + db.runCommand({count: "c", limit: 0}).n); try { print("view: " + db.runCommand({count: "v", limit: 0}).n); } catch (e) { print("view: error " + e.code + ", " + e.errmsg); } print("view limit -1: " + db.runCommand({count: "v", limit: -1}).n); ' collection: 5 view: error 15958, the limit must be positive view limit -1: 1
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      For the count command limit: 0 means no limit, and on a collection it returns the full count. The same command against a view returns error 15958, "the limit must be positive".

      Negative limits are not affected. limit: -1 on a view returns 1, which matches the collection, so zero is the only value that differs.

      Every way of writing zero gives the error, so it does not depend on the numeric type. 0, 0.0, -0.0, NumberDecimal("0") and NumberDecimal("-0") all fail the same way.

      Expected

      5, the same as the collection returns.

      Actual

      Error 15958, "the limit must be positive".

            Assignee:
            Unassigned
            Reporter:
            Daniel Frankcom (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: