title: Retrieve only the queried element in an object array in MongoDB collection and add it in another document as reference
body: <p>Suppose you have the following documents in my collection:</p>
  
  <pre><code>{  
  
  "_id":ObjectId("562e7c594c12942f08fe4192"),
  "name": "Asset1"
     "shapes":[  
        {  
       "_id": "5cf10fea4cb6352abcfe094b",
           "shape":"square",
           "color":"blue"
        },
        {  
       "_id": "5cf10fea4cb6352abcfe094c",
           "shape":"circle",
           "color":"red"
        }
     ]
  },
  
  {  
     "_id":ObjectId("562e7c594c12942f08fe4193"),
     "name": "Asset2"
     "shapes":[  
        {  
       "_id": "5c7524f76792cf28f80793e3"
           "shape":"square",
           "color":"black"
        },
        {  
       "_id": "5c7524f76792cf28f80793e4"
           "shape":"circle",
           "color":"green"
        }
     ]
  }
  }
  </code></pre>
  
  <p>I do not have problem in finding a particular color like this also it is working</p>
  
  <pre><code>  Test.find(
      {"shapes.color": "red"}, 
  
      //Match the exact color
      {
        products: {
          $elemMatch: { color: "red" }
        }
      }
    )
  </code></pre>
  
  <p>The main problem is I want to add this Asset1 and take only color red not the whole array by referencing <code>ObjectId("562e7c594c12942f08fe4192")</code> it in test2 collection. How do I do this using Mongoose?</p>
  
  <p>This is the Test2 Schema where I did referencing</p>
  
  <pre><code>const Test2Schema = new Schema({
  anothername: String,
  test1Shape: {
  type: mongoose.Schema.Types.ObjectId,
  ref: "Test"
    },
  });
  </code></pre>