In the ElemMatch matcher, if the value in the target document is not an array, the matching will always return false but the matcher verifies that the condition contains legal operators, to match the server behavior. The condition verifier permits inner operators (condition keys) to be strings or symbols, and is meant to stringify the keys before operating on them.
When the sub-operator under $elemMatch is given as a symbol, the stringification is done as part of a single check and not for all checks. Thus, the verification fails because an operator is looked up using symbol argument when the lookup table only contains string keys.
To reproduce, perform $elemMatch with sub-operator given as a symbol against an empty document.
-------
Original report:
Mongoid::Matcher::ElemMatch.matches?() didn't consistently convert input keys within its condition to Strings. This PR doesn't include a new unit test verifying this behavior because ElemMatch is clearly out of sync with the k = k.to_s pattern used in other lib/Mongoid/matcher/*.rb files. Existing examples of correctly using k = k.to_s in other of these Matcher sub-modules are: