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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.5.4
    • Fix Version/s: 2.5.5
    • Component/s: Querying
    • Environment:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      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") }

      Description

      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.

        Attachments

        1. server11986.js
          0.5 kB
          Benety Goh

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: