Backend API

Swell offers native support for the MongoDB Aggregation Pipeline; a framework for data aggregation allowing you to summarize data for reporting and other purposes.

Use the aggregate parameter to construct a pipeline according to this Mongo reference.

Example aggregation query
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/orders', {
  aggregate: [
    {
      $match: {
        $and: [
          { date_created: { $gt: '2018-01-01T00:00:00Z' } },
          { date_created: { $lt: '2019-01-01T00:00:00Z' } }
        ]
      }
    },
    {
      $group: {
        count: { $sum: 1 },
        sub_total: { $sum: 'sub_total' },
        avg_total: { $avg: 'sub_total' },
        day: { $dayOfMonth: 'date_created' },
        month: { $month: 'date_created' },
        year: { $year: 'date_created' }
      }
    }
  ]
});