Algo for sorting/compiling (and summing) an array of objects

The MongoDB Aggregation Pipeline is your best friend for this sort of thing: it’s a sequence of operations, defined as objects in an array. Each object contains one pipeline operation and the array is processed in sequence with documents being “piped” out of one operation and into the next. Sometimes, more documents come out of an operation than went in ($unwind is an example), sometimes less - it depends on the function each step performs.

Your basic pipeline would be something like this:

[
  {
    $match: {},
    $sort: { orderDate: 1 }
  },
  {
    $group: {
      _id: {
        year: { $year: '$orderDate' },
        month: { $month: '$orderDate' },
        total: { $sum: '$amount' }
      }
    }
]

In Meteor, you would do this on the server using either jcbernack:reactive-aggregate if you want reactive publication, or natively using myCollection.rawCollection().aggregate(). The easiest way to handle the latter is to use the Promise (no callback) form of that and async/await in your Meteor code.

I’m curious as to why your amount is defined as a string.