You can calculate these aggregates with either map-reduce, or the group() function. I'm using group() because it's a bit simpler and faster, however you should use map-reduce if you need to distribute the query over a sharded cluster.
First load the data:
db.orders.insert( { teamid: 100, date: "4/1", amount: 50 })
db.orders.insert( { teamid: 100, date: "4/1", amount: 40 })
db.orders.insert( { teamid: 200, date: "4/2", amount: 50 })
db.orders.insert( { teamid: 100, date: "4/2", amount: 20 })
Per team, per day:
db.orders.group({
key: { teamid: true, date: true },
reduce: function(doc, out) { out.sum += doc.amount; out.count++; },
initial: { sum: 0, count: 0 },
finalize: function(out) { out.average = out.sum / out.count }
});
To roll up daily aggregates, just change the key:
db.orders.group({
key: { date: true },
reduce: function(doc, out) { out.sum += doc.amount; out.count++; },
initial: { sum: 0, count: 0 },
finalize: function(out) { out.average = out.sum / out.count }
});