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

Support $min/max in count command

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Querying

      > 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: