title: Mongodb subdocument array lookup to subdocument array
body: <p>I am new to mongo. i have following collections.</p>
  
  <p>Document:</p>
  
  <pre><code>{
      "_id" : ObjectId("5eb256c9e519051af2eeb5f7"),
      "name" : "Income",
      "types" : [ 
          {
              "typeId" : ObjectId("5eb257a3e519051af2eeb624"),
              "name" : "W2",
              "tenantId" : null,
              "message" : "",
              "createdOn" : null,
              "createdBy" : 1.0,
              "isActive" : true
          }, 
          {
              "typeId" : ObjectId("5eb257a3e519051af2eeb639"),
              "name" : "Salary Slip",
              "tenantId" : 1,
              "message" : "",
              "createdOn" : null,
              "createdBy" : 1.0,
              "isActive" : true
          }
      ]
  }
  </code></pre>
  
  <p>Request:</p>
  
  <pre><code>{
      "_id" : ObjectId("5eb25d1fe519051af2eeb72d"),
      "employeeId" : 1234,
      "customerId" : 1275,
      "tenantId" : 1,
      "createdOn" : ISODate("2013-10-01T00:00:00.000Z"),
      "loanApplicationId" : 1.0,
      "status" : "requested",
      "message" : "Dear John, please send following documents.",
      "documents" : [ 
          {
              "typeId" : null,
              "displayName" : "W2 2016",
              "message" : "please upload salary slip for year 2016",
              "status" : "requested",
              "files" : []
          }, 
          {
              "typeId" : ObjectId("5eb257a3e519051af2eeb624"),
              "displayName" : "W2 2016",
              "message" : "please upload salary slip for year 2016",
              "status" : "requested",
              "files" : []
          }
      ]
  }
  </code></pre>
  
  <p>typeId in the document collection is the id for the document type where typeId in the request is the foreign field that can be nullable as well. how can i get the below output.</p>
  
  <pre><code>{
      "_id" : ObjectId("5eb25d1fe519051af2eeb72d"),
      "employeeId" : 1234,
      "customerId" : 1275,
      "tenantId" : 1,
      "createdOn" : ISODate("2013-10-01T00:00:00.000Z"),
      "loanApplicationId" : 1.0,
      "status" : "requested",
      "message" : "Dear John, please send following documents.",
      "documents" : [ 
          {
              "typeId" : null,
              "typeInfo": null,
              "displayName" : "W2 2016",
              "message" : "please upload salary slip for year 2016",
              "status" : "requested",
              "files" : []
          }, 
          {
              "typeId" : ObjectId("5eb257a3e519051af2eeb624"),
              "typeInfo": {
              "name": "W2" 
              },
              "displayName" : "W2 2016",
              "message" : "please upload salary slip for year 2016",
              "status" : "requested",
              "files" : []
          }
      ]
  }
  </code></pre>