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

MinKey > MaxKey in agg language

    • Query

      I was checking the sanity of how we have been merging missing and null using {$lte: ['$foo', null]}. On the bright side, it works, on the down side it appears that minKey is > maxKey (and all other values).

      > db.mk.find()
      { "_id" : ObjectId("5dd2faf88a7fad5be8c370d0"), "max" : { "$maxKey" : 1 }, "min" : { "$minKey" : 1 } }
      > db.mk.aggregate({$project: {min:1, max:1, out: {$lt: ['$min', '$max']}}})
      { "_id" : ObjectId("5dd2faf88a7fad5be8c370d0"), "max" : { "$maxKey" : 1 }, "min" : { "$minKey" : 1 }, "out" : false }
      > db.mk.aggregate({$project: {min:1, max:1, out: {$gt: ['$min', '$max']}}})
      { "_id" : ObjectId("5dd2faf88a7fad5be8c370d0"), "max" : { "$maxKey" : 1 }, "min" : { "$minKey" : 1 }, "out" : true }
      

      It appears related to this:
      https://github.com/mongodb/mongo/blob/990b2ef30d7b8fa4db6af6d79da80e3664df9c21/src/mongo/bson/bsontypes.h#L67

      My assumption is that somewhere we are treating BSONType as unsigned, so that -1 becomes MAX_INT.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            patrick.meredith@mongodb.com Patrick Meredith
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: