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

Add Feature Flag: Mongoid::Contextual::Aggregable::Mongo#sum does not return nil as expected for Mongoid::Document#none

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.4.0
    • Affects Version/s: 7.0.4
    • Component/s: Query
    • Environment:
      Ruby 2.5.0, Rails 5.2.3
    • Fully Compatible

      Given the minimal example

      class Product
        include Mongoid::Document
      
        flield :price, type: Integer
      end
      

      I observe

      2.5.0 :001 > Product.all.limit(1).sum('price')
       => 300
      2.5.0 :002 > Product.none.sum('price')
       => "price" # <-- unexpected
      

      I think the intended result by Mongoid authors would be nil as indicated here:
      https://github.com/mongodb/mongoid/blob/4350b9167eb6fe34bc93ed44a428557f63fa6c30/lib/mongoid/contextual/aggregable/mongo.rb#L28

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            larnold@givve.com Leo Arnold
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: