title: $lookup on object array with table
body: <p>I have data object that contains array. And I have providers table.</p>
  <ol>
  <li><p>if array's Id should equals to provider's table id <code>Id == id</code></p>
  </li>
  <li><p>if id is repeated take the repeated count as <code>membersCounts</code> else <code>membersCounts = 0</code></p>
  </li>
  <li><p>Add the <code>membersCounts</code> with data object</p>
  </li>
  </ol>
  <p><strong>data object</strong></p>
  <pre><code>const data = {
    Milk: [
      {
        Id: 1,
        name: 'a'
      },
      {
        Id: 2,
        name: 'b'
      },
      {
        Id: 3,
        name: 'c'
      },
      {
        Id: 4,
        name: 'd'
      },
      {
        Id: 52,
        name: 'e'
      }
    ],
    Grocery: [
      {
        Id: 8,
        name: '2a'
      },
      {
        Id: 22,
        name: '2b'
      },
      {
        Id: 32,
        name: '2c'
      },
      {
        Id: 42,
        name: '2d'
      }
    ]
  }
  </code></pre>
  <p><strong>providers table</strong></p>
  <pre><code>const providers = [
    {
      id: 1,
      status: 'active'
    },
    {
      id: 1,
      status: 'active'
    },
    {
      id: 1,
      status: 'active'
    },
    {
      id: 1,
      status: 'active'
    },
    {
      id: 4,
      status: 'active'
    },
    {
      id: 2,
      status: 'active'
    },
    {
      id: 3,
      status: 'active'
    },
    {
      id: 3,
      status: 'active'
    },
    {
      id: 52,
      status: 'active'
    },
    {
      id: 1,
      status: 'active'
    }
  ]
  
  </code></pre>
  <p><strong>here javascript code</strong></p>
  <p>this code is working good but I want perform this with mongodb queries. So that performance is good .
  Is possible to do with mongodb query. I need to covert the javascript code to mongodb query.</p>
  <pre><code>getMembersWithVendors(data, providers) {
      for (var key in data) {
        var arr = data[key]
        arr.forEach((element) =&gt; {
          element.memberCounts = 0
          element.new = true
          providers.map((el) =&gt; {
            if (element._id == el.vendorId) {
              (element.memberCounts = element.memberCounts + 1),
                (element.new = false)
            }
          })
        })
      }
      return data
    }
  </code></pre>
  <p><strong>output</strong></p>
  <pre><code>{ Milk:
     [ { Id: 1, name: 'a', memberCounts: 5 },   
       { Id: 2, name: 'b', memberCounts: 1 },   
       { Id: 3, name: 'c', memberCounts: 2 },   
       { Id: 4, name: 'd', memberCounts: 1 },   
       { Id: 52, name: 'e', memberCounts: 1 } ],
    Grocery:
     [ { Id: 8, name: '2a', memberCounts: 0 },  
       { Id: 22, name: '2b', memberCounts: 0 },
       { Id: 32, name: '2c', memberCounts: 0 },
       { Id: 42, name: '2d', memberCounts: 0 } ] }
  </code></pre>
  <p>Thanks !!</p>