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

count() broken with $min and $max

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.4.7, 2.5.4
    • Component/s: Querying, Shell

      Prepending description from SERVER 9548

      > db.docs.drop()
      > for (var i=0; i<10; i++) { db.docs.insert({number: i}) }
      > db.docs.find()
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e3"), "number" : 0 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e4"), "number" : 1 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e5"), "number" : 2 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e6"), "number" : 3 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e7"), "number" : 4 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e8"), "number" : 5 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e9"), "number" : 6 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7ea"), "number" : 7 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7eb"), "number" : 8 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7ec"), "number" : 9 }
      > db.docs.count()
      10
      
      > db.docs.find().max({number: 4})
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e3"), "number" : 0 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e4"), "number" : 1 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e5"), "number" : 2 }
      { "_id" : ObjectId("51834d678d284e5c5e3ea7e6"), "number" : 3 }
      

      So far so good.

      > db.docs.find().max({number: 4}).count()
      10
      

      I would like this count to return 4. Instead it returns 10.

      ----------
      (original description)
      see jstests/testminmax.js

      wrong result

      if this is hard to fix and mainly for mongos, we could uassert "not implemented", but we can't return wrong answer.

        1. testminmax.js
          0.9 kB
          Benety Goh

            Assignee:
            asya.kamsky@mongodb.com Asya Kamsky
            Reporter:
            dwight@mongodb.com Dwight Merriman
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: