title: MongoDB Query double nested documents in array
body: <p>I was wondering how I can query from an embedded document inside an array. I have following structure:</p>
  
  <pre><code>{ "targetId" : 2, "metaData" : [ {     "key" : "id",     "value" : 1 },     {     "key" :        "name",     "value" : "Parisa" },     {     "key" : "img",     "value" : {     "imgid" : 1,         "imgName" : "img1" } } ] 
  </code></pre>
  
  <p>I could search simple key-values like key = id and value =1, but I could not search based on the values with embedded document e.g. key="img"</p>
  
  <p>I tried following query but it does not work:</p>
  
  <pre><code>db.test.find({"metaData":{$elemMatch:{"key":"img", "value":{"imgid":1}}}})
  </code></pre>
  
  <p>Could you please help me!</p>