If the following is used
Analytic.collection.map_reduce(map, reduce,
:query => {:page => subclass_name},
:sort => [[:pageviews, Mongo::DESCENDING]]).find.to_a
it won't sort by pageviews
. Alternatively, if it is array of hash:
Analytic.collection.map_reduce(map, reduce,
:query => {:page => subclass_name},
:sort => [{:pageviews => Mongo::DESCENDING}]).find.to_a
it won't work either. I think the reason it has to be an array is to specify the first field to sort by, etc. I also tried just a flat array instead of an array of array like in the first code listing up above and it didn't work either.
Is it not working? This is the spec: http://api.mongodb.org/ruby/current/Mongo/Collection.html#map_reduce-instance_method