can it sort by id?
[1] https://www.mongodb.com/docs/manual/reference/operator/aggre...
[2] https://www.mongodb.com/docs/manual/reference/method/ObjectI...
There's no limit on number of sortable documents. Use an index to sort and it'll also be fast and use no extra memory. If you want to do an in memory sort there are memory limits, but you can also tell it to overflow to disk.
I've removed that part of my comment. Appreciate the correction.