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

$type parsing should reject non-integral type codes

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc1
    • Affects Version/s: 3.5.10
    • Component/s: Querying
    • Fully Compatible
    • ALL
    • Query 2017-10-23

      Instead of failing, $type parsing converts a non-integral type code to -1, which is the type code for MinKey:

      > db.c.drop()
      true
      > db.c.insert({a: 1})
      WriteResult({ "nInserted" : 1 })
      > db.c.insert({a: MinKey()})
      WriteResult({ "nInserted" : 1 })
      > db.c.insert({a: "foo"})
      WriteResult({ "nInserted" : 1 })
      > db.c.insert({a: MaxKey()})
      WriteResult({ "nInserted" : 1 })
      > db.c.find({a: {$type: -1}})
      { "_id" : ObjectId("596925106d078d9cebb74764"), "a" : { "$minKey" : 1 } }
      > db.c.find({a: {$type: 1.5}})
      { "_id" : ObjectId("596925106d078d9cebb74764"), "a" : { "$minKey" : 1 } }
      > db.c.find({a: {$type: 2.1}})
      { "_id" : ObjectId("596925106d078d9cebb74764"), "a" : { "$minKey" : 1 } }
      

      This behavior is due to the parser implementation here:

      https://github.com/mongodb/mongo/blob/9f317c119bef0a66ca1a2ed6617df87b2ed557d4/src/mongo/db/matcher/expression_parser.cpp#L703-L705

            Assignee:
            blake.oler@mongodb.com Blake Oler
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: