title: Query Mongo for multiple key value pair combinations in array field
body: <p>I am trying to query for Mongo documents based on 1 many key value pairs over a large collection of documents.</p>
  
  <p>I am storing the values in an array called descriptors. I cannot figure out to write the query to consistently return results.</p>
  
  <p>Basically I am trying to write the following SQL query in Mongo</p>
  
  <pre><code> select * from descriptors where 
      (id=123 and value="Latest based on new infor")
    or 
      (id=3221 and value="Latest new info")
  </code></pre>
  
  <p>I have tried the following:</p>
  
  <pre><code>db.collection.find({$or: [
         {  descriptors:
           {
            '$elemMatch':
              {
                 id: 123,
                 value: 'Latest based on new infor',
  
              }
           }
         },
         {  descriptors:
          {
            '$elemMatch':
              {
                 id: 3221,
                 value: 'Latest new info',
  
              }
          }
         }
      ]
  }
  </code></pre>
  
  <p>Here are sample documents.</p>
  
  <pre><code>{ 
          "_id" : ObjectId("569d62673b020a47f0401325"), 
  
          "descriptors" : [
              {
                  "id" : 123, 
                  "name" : "Version", 
                  "value" : "Latest based on new infor", 
                  "parent" : null
              }, 
              {
                  "id" : 345, 
                  "name" : "Eligibility Criteria", 
                  "value" : "Really qualified ", 
                  "parent" : null
              }
          ],      
      }
  
      { 
          "_id" : ObjectId("569dac2e4e6247c01bbac47f"), 
  
          "descriptors" : [
              {
                  "id" : 3221, 
                  "name" : "Version", 
                  "value" : "Latest new info", 
                  "parent" : null
              }, 
              {
                  "id" : 345, 
                  "name" : "Eligibility Criteria", 
                  "value" : "Different Value", 
                  "parent" : null
              }
          ], 
      }
  
      { 
          "_id" : ObjectId("56bce4df7aae8369d8fc705d"), 
          "descriptors" : [
              {
                  "id" : 3221, 
                  "name" : "Version", 
                  "value" : "Latest based on new infor", 
                  "parent" : null
              }, 
              {
                  "id" : 345.0, 
                  "name" : "Eligibility Criteria", 
                  "value" : "Really qualified", 
                  "parent" : null
              }
          ], 
  
      }
  </code></pre>
  
  <p>Any help would be appreciated,
  gsvi</p>