-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: 2.4.3
-
Component/s: Public API
-
None
-
Environment:MRI 2.3
-
3
I've got two annoyances with the map reduce api, ie when you do something like
collection.find().map_reduce(map_function, reduce_function)
1. the returned object is an Enumerable, but it has accessors that shadow two common Enumerable methods: `map` and `reduce`.
I want to use these methods way more often than I want to use the accessor methods. I know I can call `collect` or `inject` instead, but it's very easy to forget this (and typically leads to obscure error), and means that everything needs to know whether this is a normal Enumerable or an Enumerable where map doesn't do what you want.
2. There's no way of triggering the map reduce without retrieving a cursor. I've got lots of code that uses map reduce to build / update data retrieved by other processes (using the options that write the output to a collection): the code that calls map reduce doesn't actually care about the result, but now has to do
map_reduce(...).first
Even when I do want to iterate over the output collection I frequently want to apply some conditions, limit the output etc. For all these reasons I'd like an `execute` method that just runs the map reduce (the same niggle applies to the aggregate api).
For the first issue renaming the accessors would do the job, however I don't know if you consider that part of the public api