I have code similar to the example here http://mongoosejs.com/docs/api.html#model_Model.mapReduce
The main difference is that I'm trying to only save values which are within the top five.
For example, if the resulting mapReduce collection generates the following:
{
"_id": "1",
"value": 6
}
{
"_id": "2",
"value": 32
}
{
"_id": "3",
"value": 1
}
{
"_id": "4",
"value": 5
}
{
"_id": "5",
"value": 6
}
{
"_id": "6",
"value": 7
}
What would be the best method for only saving the documents which have a value key within the top five to the mapReduce results?
I've tried using the sort option but that produces this error:
[MongoError: exception: could not create cursor over [db].[collection] for query : {} sort : { value: 1 }]
At first I thought maybe you should pass in a "sort" arg to your filter object, but then I came across this: MongoDB, MapReduce and sorting