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

CanonicalQuery::canonicalize() rejects $elemMatch for DBRefs

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

      I encountered this on a 2.5.5 nightly, but I imagine the change was introduced somewhere in the 2.5.x branch.

      > db.foo.find({ friends: { $elemMatch: { $ref: "people", $id: ObjectId('52b85ca3e84df160228b493b'), $db: "doctrine_odm_tests" } } })
      error: {
      	"$err" : "Can't canonicalize query: BadValue unknown top level operator: $ref",
      	"code" : 17287
      }
      

      I don't believe there is a case where $elemMatch would have another operator as its immediate child, so perhaps this is just due to how the canonicalizer walks the query object. I noticed that it does not error out for the following queries:

      > db.foo.find({ friend: { $ref: "people", $id: ObjectId('52b85ca3e84df160228b493b'), $db: "doctrine_odm_tests" } })
      > db.foo.find({ friend: { $in: [{$ref: "people", $id: ObjectId('52b85ca3e84df160228b493b'), $db: "doctrine_odm_tests" }]}})
      

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: