CanonicalQuery::canonicalize() rejects $elemMatch for DBRefs

XMLWordPrintableJSON

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

      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
              Reporter:
              Jeremy Mikola
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: