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

{$type: Object} operator does not work with dot notation on array elements

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.4.5
    • Fix Version/s: 2.5.5
    • Component/s: Querying
    • Environment:
    • Operating System:
      ALL

      Description

      Queries for BSON type Object on array elements specified using the dot notation and the $type operator do not match valid documents in a collection.

      Example query:

      {a: {'b.0': {$type: 3}}} // 3 is BSON type for Object - does not match documents
      {a: {'b.0': {$type: 2}}} // 2 is BSON type for String - works fine

      http://docs.mongodb.org/manual/core/document/#document-dot-notation

      http://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type

      ----------------
      Problem:
      2.4 executes equality matches differently depending on the structure of the document.

      NOTE This appears to be fixed in 2.5.4-Pre

      Reproduce:

      db.q.drop()
      db.q.insert({ "b" : [ 314159265011, { "a" : "" } ] })
      db.q.insert({ "b" : [ true, { "b" : "I took a speed reading course and read \"War and Peace\" in twenty minutes. It involves Russia." } ] })
      db.q.insert({ "b" : [ {}, { "b" : Date(1380451200000) } ] })
      db.q.insert({ "b" : [ 314159265004, { "d" : { "d" : 0, "c" : 314159265012 } } ] })
      db.q.insert({ "b" : [ 314159265005, { "d" : { "d" : "We are what we repeatedly do; excellence, then, is not an act but a habit." } }, "My pessimism extends to the point of even suspecting the sincerity of the pessimists.", "" ] })
      db.q.insert({ "b" : [ 1, { "a" : {} } ] })
      db.q.insert({ "b" : [ "", { "2" : { "d" : { "d" : {} } } } ] })
      db.q.insert({ "b" : [ "You must be the change you wish to see in the world.", { "a" : true }, false ], "a" : 1 })
      db.q.insert({ "b" : [ false, { "c" : "" } ] })
      db.q.insert({ "b" : [ 314159265009, {"d" : Date(1380412800000) }, 314159265000 ] })
      db.q.insert({ "b" : [ Date(0), { "b" : 0 } ] })
      db.q.insert({ "b" : [ Date(1380451200000), { "d" : 0 } ] })
      db.q.insert({ "b" : [ 4.940656458412465e-324, { "a" : "To the man who only has a hammer, everything he encounters begins to look like a nail." } ], "c" : Date(1380451200000) })
      db.q.insert({ "b" : [ { "b" : "" }, { "0" : { "c" : "Asking a working writer what he thinks about critics is like asking a lamppost how it feels about dogs." } } ] })
      db.q.insert({ "b" : [ "", { "a" : 4.940656458412465e-324 } ] })
      db.q.insert({ "b" : [ Date(0), {} ] })
      db.q.insert({ "b" : [ {}, { "c" : Infinity } ] })
      db.q.insert({ "b" : [ 1, { "c" : [ {} ] } ] })

      Query 1

      db.q.find( { "b.1" : { $type : 3 } } ).count()

      2.4.5: 18 docs returned
      2.5.4-Pre: Zero docs returned

      Query 2

      db.q.find( { "x" : { $type : 3 } } ).count()

      2.4.5: Zero docs returned
      2.5.4-Pre: Zero docs returned

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: