Aggregate to Create Groups of Documents by Size
<p>I have a collection called "orders". Each order in this collection has an array of product ids. For example:</p>

<pre><code>&gt; db.orders.find()
[
  { _id: 1, products: [10, 11, 12] },
  { _id: 2, products: [13, 14] },
  { _id: 3, products: [15] },
  { _id: 4, products: [16, 17] }
]
</code></pre>

<p>Now, I want to create a collection where I group up to <code>n</code> products, where every order's products must be in the same document, and n will always be greater than the number of products in any order.</p>

<p>so, in the example above, say I specified <code>n</code> as 3. The result would look like:</p>

<pre><code>[{
  orders: [1],
  products: [10, 11, 12]
}, {
  orders: [2, 3],
  products: [13, 14, 15]
}, {
  orders: [4],
  products: [16, 17]
}]
</code></pre>

<p>Is this possible with a mongo aggregation?</p>