title: MongoDB Issue in fetching data from array having objects as elements
body: <p>I have a DB as “link” and a collection within this DB as “products”. The “products” collection is having below records -</p>
  
  <p><a href="https://i.stack.imgur.com/lHsXC.jpg" rel="nofollow noreferrer">MongoDBCollectionStructure</a></p>
  
  <p>Now I have an input array with below 3 ‘productconfig._id’ –
      5984b2f0ca0a093c74cb4395, 598d57c8b541eb3e58e98cf7, 5984b48eca0a093c74cb4397
  Now based on that, I want my output like this –</p>
  
  <p><a href="https://i.stack.imgur.com/rbr1m.jpg" rel="nofollow noreferrer">MongoDBExpectedResult</a></p>
  
  <p>(Note that I don’t want the 3rd object of productconfig Array from document 1)</p>
  
  <p>I had tried below 2 queries -</p>
  
  <ol>
  <li><p>db.products.find({"productconfig._id":{$in: [ObjectId("5984b2f0ca0a093c74cb4395"), ObjectId("598d57c8b541eb3e58e98cf7"), ObjectId("5984b48eca0a093c74cb4397")]}},{"name":1, "productconfig.$":1}).pretty()</p></li>
  <li><p>db.products.find({"productconfig":{$elemMatch: {"_id": {$in: [ObjectId("5984b2f0ca0a093c74cb4395"), ObjectId("598d57c8b541eb3e58e98cf7"), ObjectId("5984b48eca0a093c74cb4397")]}}}},{"name":1, "productconfig.$":1}).pretty()</p></li>
  </ol>
  
  <p>But these queries are not returning the currect output as the output is not having productconfig._id=598d57c8b541eb3e58e98cf7 record.</p>
  
  <p>Please help.</p>
  
  <p>I know there is a similar question asked in in below link -
  <a href="https://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection">Retrieve only the queried element in an object array in MongoDB collection</a></p>
  
  <p>However I am not able to apply that $filter logic in here. Appreciate if someone can please let me know the query</p>