title: Mongodb $in against a field of objects of array instead of objects of array
body: <pre><code>arr=[{field1:&lt;value1&gt;,field2:&lt;value2}.....]
  </code></pre>
  
  <p>I want to use the <code>$in</code> operator against the <code>field1</code> of <code>arr</code>. I know I could create a dummy array and push the <code>field1</code> values in the dummy array. But is there a way to use the <code>$in</code> operator against a particular field of an array? </p>
  
  <p>The <code>arr</code> array is no way related to the collection.</p>
  
  <p>I want to query all the documents on a particular field whose value is in the <code>field1</code> of <code>arr</code> - field1 should be in the right hand side of operator <code>$in</code></p>
  
  <p>Example:</p>
  
  <pre><code>arr=[{name:'foo',location:'NY'},{name:'bar',location:'LA'},{name:'foobar',location:'NZ'}]
  
  db.collection.find({fieldx:&lt;Here I want some method to obtain all documents whose fieldx values are in the location field of arr&gt;})
  </code></pre>
  
  <p>The output should contain documents whose <code>fieldx</code> values are present in the <code>location</code> field of <code>arr</code>.</p>
  
  <p>The ouput of the query should be</p>
  
  <pre><code>[{... 
      fieldx:'NY',
  ...
  },
  {...
      fieldx:'LA',
  ...
  },
  {...
      fieldx:'NZ',
  ...
  }]
  </code></pre>
  
  <p><code>fieldx</code> is the field in the collection I am querying on. It is not a field of the array I'm providing(<code>arr</code>). I want to match this to a field(<code>location</code>) of array - <code>arr</code> I'm providing the query.</p>