title: Group by id with inner array
body: <p>Hi I am trying to create a query that incorporates three different collections and groups them in a very specific way and I am not sure if this is possible. Here is my code so far:</p>
  <p>First I get all the required info from all my collections</p>
  <pre><code>CheckOutOrder.aggregate([
  {
                  $lookup:{
                      from:'e_orders',
                      localField:'idReceipt',
                      foreignField:'idReceipt',
                      as:'orders'
                  }
              },
              {
                  $addFields:{
                      'idItem':{
                          $toObjectId:'$idItem'
                      }
                  }
              },
              {
                  $lookup:{
                      from:'e_menu_items',
                      localField:'idItem',
                      foreignField:'_id',
                      as:'items'
                  }
              }
  ])
  </code></pre>
  <p>For reference, <code>e_orders</code> are unique results but <code>CheckOutOrder</code> are all the individual items on each order.</p>
  <p>Here is the example of an unwind result:</p>
  <pre><code>[
    {
      _id: new ObjectId(&quot;61d8d43f7eb82e503c064716&quot;),
      idReceipt: 2,
      idItem: new ObjectId(&quot;61d7fad55bda9c3be60b14fd&quot;),
      is_open: 0,
      date_added: 2022-01-08T00:01:03.246Z,
      __v: 0,
      orders: {
        _id: new ObjectId(&quot;61d8d44f7eb82e503c06471e&quot;),
        idReceipt: 2,
        was_deliver: 1,
        was_paid: 1,
        id_payment: 1,
        delTime: '17:01',
        orderComment: '',
        orderStat: 0,
        date_added: 2022-01-08T00:01:19.347Z,
        __v: 0
      },
      items: {
        _id: new ObjectId(&quot;61d7fad55bda9c3be60b14fd&quot;),
        menuItem: 'Scallion Pancake',
        description: 'for my bby',
        price: 10,
        id_cat: 1,
        is_active: 1,
        date_added: 2022-01-07T08:33:25.554Z,
        date_modified: 2022-01-07T08:33:25.554Z,
        __v: 0
      }
    },
    {
      _id: new ObjectId(&quot;61d8d7d2b725b1c73d4679f7&quot;),
      idReceipt: 3,
      idItem: new ObjectId(&quot;61d7f9205bda9c3be60b14ed&quot;),
      is_open: 0,
      date_added: 2022-01-08T00:16:18.028Z,
      __v: 0,
      orders: {
        _id: new ObjectId(&quot;61da350ec2dea6bb5694acc8&quot;),
        idReceipt: 3,
        was_deliver: 1,
        was_paid: 1,
        id_payment: 1,
        delTime: '21:06',
        orderComment: '',
        orderStat: 0,
        date_added: 2022-01-09T01:06:22.054Z,
        __v: 0
      },
      items: {
        _id: new ObjectId(&quot;61d7f9205bda9c3be60b14ed&quot;),
        menuItem: 'Molletes',
        description: 'Frijoles, queso y salsa',
        price: 18,
        id_cat: 1,
        is_active: 1,
        date_added: 2022-01-07T08:26:08.990Z,
        date_modified: 2022-01-07T08:26:08.990Z,
        __v: 0
      }
    },
    {
      _id: new ObjectId(&quot;61d8d90db725b1c73d4679fd&quot;),
      idReceipt: 3,
      idItem: new ObjectId(&quot;61d7f9205bda9c3be60b14ed&quot;),
      is_open: 0,
      date_added: 2022-01-08T00:21:33.865Z,
      __v: 0,
      orders: {
        _id: new ObjectId(&quot;61da350ec2dea6bb5694acc8&quot;),
        idReceipt: 3,
        was_deliver: 1,
        was_paid: 1,
        id_payment: 1,
        delTime: '21:06',
        orderComment: '',
        orderStat: 0,
        date_added: 2022-01-09T01:06:22.054Z,
        __v: 0
      },
      items: {
        _id: new ObjectId(&quot;61d7f9205bda9c3be60b14ed&quot;),
        menuItem: 'Molletes',
        description: 'Frijoles, queso y salsa',
        price: 18,
        id_cat: 1,
        is_active: 1,
        date_added: 2022-01-07T08:26:08.990Z,
        date_modified: 2022-01-07T08:26:08.990Z,
        __v: 0
      }
    }
  ]
  </code></pre>
  <p>As you can see there is three results for the query that are 2 for <code>idReceipt:3</code> and 1 for <code>idReceipt:2</code>. Is there a way to group them to be only two results but with the items on an array inside?</p>
  <p>Like this:</p>
  <pre><code>idReceipt,
  was_deliver,
  was_paid,
  id_payment,
  array[
    items.menuItem,
    items.price
  ]
  </code></pre>
  <p>I have been trying for several hours but I don't seem to get to any combination of groups to get that. I know that I can just get the total result with <code>$project</code> and then group it on my ejs but I want to see if this is possible</p>