title: how to query the key exists in mongoid or mongo(ruby)
body: <pre><code>{&quot;_id&quot;:{&quot;$oid&quot;:&quot;5ee9e17e88adc3a1d6c2a39f&quot;},&quot;title&quot;:&quot;test&quot;,&quot;products&quot;:{&quot;car&quot;:&quot;yes hello&quot;}}
  </code></pre>
  <p>how can I query the documents which have the key car use mongo _id or mongo?
  I tried</p>
  <pre><code>    irb(main):042:0&gt; x = client[:materials].find({&quot;products.car&quot;:{$exists=&gt;true}})
  =&gt; #&lt;Mongo::Collection::View:0x47269370736460 namespace='db.materials' @filter={&quot;products.car&quot;=&gt;{nil=&gt;true}} @options={}&gt;
  irb(main):043:0&gt; x.count
  Traceback (most recent call last):
          1: from (irb):43
  BSON::InvalidKey (NilClass instances are not allowed as keys in a BSON document.)
  </code></pre>
  <p>and I don't know how to do it with mongo _id or mongo. and puzzled about the error message</p>