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

$ projection operator doesn't validate corresponding field in query specifier in 2.5

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.5
    • Affects Version/s: 2.5.4
    • Component/s: Querying
    • Environment:
    • Fully Compatible
    • ALL
    • Hide

      2.4.9-pre-

      > db.g.insert({arr:[5]})
      > db.g.find({arr:{$gt:4}},{"arr.$":1})
      { "_id" : ObjectId("52a1164abed6d595b15ec697"), "arr" : [  5 ] }
      > db.g.find({arr:{$size:1}},{"arr.$":1})
      error: {
      	"$err" : "positional operator (arr.$) requires corresponding field in query specifier",
      	"code" : 16352
      }
      

      2.5.5-pre-

      > db.g.insert({arr:[5]})
      Insert WriteResult({ "ok" : 1, "n" : 1 })
      > db.g.find({arr:{$gt:4}},{"arr.$":1})
      { "_id" : ObjectId("52a1164add47ad0373e22ae8"), "arr" : [ 5 ] }
      > db.g.find({arr:{$size:1}},{"arr.$":1})
      { "_id" : ObjectId("52a1164add47ad0373e22ae8") }
      
      Show
      2.4.9-pre- > db.g.insert({arr:[5]}) > db.g.find({arr:{$gt:4}},{ "arr.$" :1}) { "_id" : ObjectId( "52a1164abed6d595b15ec697" ), "arr" : [ 5 ] } > db.g.find({arr:{$size:1}},{ "arr.$" :1}) error: { "$err" : "positional operator (arr.$) requires corresponding field in query specifier" , "code" : 16352 } 2.5.5-pre- > db.g.insert({arr:[5]}) Insert WriteResult({ "ok" : 1, "n" : 1 }) > db.g.find({arr:{$gt:4}},{ "arr.$" :1}) { "_id" : ObjectId( "52a1164add47ad0373e22ae8" ), "arr" : [ 5 ] } > db.g.find({arr:{$size:1}},{ "arr.$" :1}) { "_id" : ObjectId( "52a1164add47ad0373e22ae8" ) }

      Version 2.5 of MongoDB doesn't seem to look to see if there's a corresponding field to match with the $ projection operator. Consequently, malformed projections involving the $ operator return documents in version 2.5, but an error is thrown in 2.4.

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            luke.lovett Luke Lovett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: