title: MongoDB elemMatch subdocuments
body: <p>I have the following data structure</p>
  
  <pre><code>{
      "_id" : ObjectId("523331359245b5a07b903ccc"),
      "a" : "a",
      "b" : [
          {
              "c" : {
                  "_id" : ObjectId("5232b5090364678515db9a82"),
                  "d" : "d1"
              }
          },
          {
              "c" : {
                  "_id" : ObjectId("5232b5090364678515db9a83"),
                  "d" : "d2"
              }
          }
      ]
  }
  </code></pre>
  
  <p>For the following queries, mongo returns</p>
  
  <pre><code>&gt; db.test.find({b : {$elemMatch : {'c.d': 'd1'}}}).count();
  1
  &gt; db.test.find({b : {$elemMatch : {c: {d: 'd1'}}}}).count();
  0
  </code></pre>
  
  <p>Unfortunately, for the following statements</p>
  
  <pre><code>B b = new B();
  C c = new C();
  b.c = c;
  b.c.d = "d1";
  createQuery().field("b").hasThisElement(b).asList();
  </code></pre>
  
  <p>Morphia generates db.test.find({b : {$elemMatch : {c: {d: 'd1'}}}}) which returns 0 match.</p>
  
  <p>Is this a mongo bug or a morphia bug? Is there any workaround for me to get the matched document?</p>
  
  <ul>
  <li>Please note that in the real world practice, I have 2 conditions for elemMatch, hence I have to use "elemMatch", not "dot notation" match. The above is just to simplify my case for easy viewing. </li>
  <li>I'm running Mongodb 2.4.6 and Morphia 1.2.3</li>
  </ul>
  
  <p>Thanks!</p>