Actually your real problem here is that index is not being selected. You can check this via the explain
option ( available in MongoDB 2.6 or actually from MongoDB 2.4.9 though not documented ) from the db.runCommand
form of invoking aggregate.
With MongoDB it is very important to specify the field you wish to use in a index when matching first. So an index defined as:
collection.ensureIndex({ "active": 1 })
Or even with -1
would get selected in this case. Your index does not because you did not reference any of the other fields.
This can force over larger selections, when the optimizer recognizes this would be the optimal case, but this actually appears to be broken in current 2.6 releases (until fixed).
Addendum: So there is possibly a "sorting" component to be involved, but that is more about how you specify the compound index yet again. To ensure you "timestamp" values are in order for the grouping boundaries, make sure you include that after the initial selector, as in:
collection.ensureIndex({ "active": -1, "timestamp": -1 })
In your required order.