title: MarkLogic node.js api - group by sum
body: <p>Something similar to my question here: <a href="https://stackoverflow.com/questions/40715822/marklogic-node-js-api-group-by-and-sort-by-count">MarkLogic node.js api - group by and sort by count</a></p>
  
  <p>I have documents in Marklogic with fields <em>name</em> and <em>amount</em>. I want to get the total amount for each name. Basically in SQL it would be </p>
  
  <pre><code>select name, sum(amount) from table group by name
  </code></pre>
  
  <p>I have <strong>range indexes</strong> for both <em>name</em> and <em>amount</em>.
   For getting sum aggregates, the documentation suggests something like <strong>valuesBuilder.fromIndexes('amount').aggregates('sum')</strong>, but this only gets the sum for all records, instead of per name like I want.</p>
  
  <p>Any advice?</p>