OR query matching nil or “” with Mongoid still matches “”?
问题 I'm trying to write a query for an embedded Mongoid::Document which finds any record where the "address" field is neither nil nor "". Using a combination of the MongoDB documentation, this issue in the Mongoid bug reports, and the Mongoid documentation, I think that something like this should work: scope :with_address, where("$or" => [{:address => {"$ne" => nil}}, {:address => {"$ne" => ""}}]) When I run this, the selector looks ok: 1.9.2p290 :002 > report.document.records.with_address => #