title: Couchbase aggregation of nested field
body: <p>I'm completely new to Couchbase and, whilst learning pretty quickly, I'm struggling to see if it's possible to create a query / view to aggregate data stored in a nested field, where the structure of the nested field is uncertain.</p>
  
  <p>For example, considering the following documents:</p>
  
  <pre><code>[
      {
          "customer": 1,
          "user": 21,
          "group": 2,
          "data": {
              "cat": 2,
              "dog": 1
          }
      },
      {
          "customer": 1,
          "user": 22,
          "group": 3,
          "data": {
              "cat": 1,
              "rabbit": 3
          }
      },
      {
          "customer": 1,
          "user": 23,
          "group": 2,
          "data": {
              "budgie": 1,
              "mouse": 1,
              "dog": 1
          }
      }
  ]
  </code></pre>
  
  <p>I would like to have a query that would, for instance, group by "group" and "customer" and produce a result similar to the following:</p>
  
  <pre><code>[
      {
          "customer": 1,
          "group": 2,
          "data": {
              "cat": 2,
              "dog": 2,
              "budgie": 1,
              "mouse": 1
          }
      },
      {
          "customer": 1,
          "group": 3,
          "data": {
              "cat": 1,
              "rabbit": 3
          }
      }
  ]
  </code></pre>
  
  <p>The top level data (customer / user / group / data) will be static and always contain those fields, but, the items in "data" are free-form.</p>
  
  <p>Is this something that's possible natively in Couchbase, or would I need to do this programmatically with the client application?</p>
  
  <p>I've settled for the programmatic solution for the time being but, would be nice to know.</p>