Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5556

#tally should support splatting array results

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      The #tally method currently does this:

      class Band
        include Mongoid::Document
        field :genres, type: Array
      end
      
      Band.create!(genres: [1, 2])
      Band.create!(genres: [1, 2])
      Band.create!(genres: [1, 3])
      
      Band.tally(:genres)
        #=> { [1, 2] => 2,
              [1, 3] => 1 }

      This is perhaps useful in some cases, but usually you'd want to see Array values split out. I'd like to add this:

       

       

      Band.tally(:genres, splat_arrays: true)
        #=> { 1 => 3,
              2 => 2,
              3 => 1 }

       

      The change can be done with low complexity.

      The default value of :splat_arrays would be false, preserving the existing behavior.

      I may call this option "unwind" instead because that's the MongoDB operator name that does this. TBD.

            Assignee:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: