Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1234

map_reduce api is unfriendly

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.4.3
    • Fix Version/s: 2.5.0
    • Component/s: Public API
    • Labels:
      None
    • Environment:
      MRI 2.3
    • Story Points:
      3

      Description

      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

        Attachments

          Activity

            People

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            fcheung Frederick Cheung
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: