As far as I know, I can\'t specify a complex sort function in Mongo so I have to use a map/reduce query which feels a bit useless since I don\'t even use the reduce portion. Thi
Normally sort
in mongodb mapreduce applied before the map, literally they are applied to the input data not the output.
From mongodb docs
[, sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>]
[, limit : <number of objects to return from collection>]
So if you want to sort & limit the map reduce output, you must store the result in temp collection. I dont think its possible to apply the sort & limit to the inline
mapreduce output since it runs on RAM.
EDIT:
There is a open issue (Add support for sorting and limiting inline map/reduce) in mongodb Jira regarding this. Have a look.