Improve backing query when using aggregation helpers

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Associations, Query
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The given code

      class User
        include Mongoid::Document
      
        has_many :cgm_evgs
      end
      
      class CgmEvg
        include Mongoid::Document
      
        field :timestamp, type: Date
      
        belongs_to :user
      end
      
      User.find(_id: u1.id).cgm_evgs.min(:timestamp).to_a
      

      generates the following command:

      {
      	"aggregate":"cgm_evgs",
      	"pipeline":[
      		{"$match":{"user_id":{"$oid":"65a7dfcfe61d72729750604a"},"timestamp":{"$exists":true}}},
      		{
      			"$group":{
      				"_id":"timestamp",
      				"count":{"$sum":1},
      				"max":{"$max":"$timestamp"},
      				"min":{"$min":"$timestamp"},
      				"sum":{"$sum":"$timestamp"},
      				"avg":{"$avg":"$timestamp"}
      			}
      		}
      	]
      }
      

      The command does not reflect the code.

              Assignee:
              Unassigned
              Reporter:
              Dmitry Rybakov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated: