lib/mongoid/contextual/aggregable/mongo.rb in mongoid-7.2.6 vs lib/mongoid/contextual/aggregable/mongo.rb in mongoid-7.3.0
- old
+ new
@@ -9,20 +9,22 @@
# Get all the aggregate values for the provided field.
#
# @example Get all the aggregate values.
# aggregable.aggregates(:likes)
+ # # => {
+ # # "count" => 2.0,
+ # # "max" => 1000.0,
+ # # "min" => 500.0,
+ # # "sum" => 1500.0,
+ # # "avg" => 750.0
+ # # }
#
# @param [ String, Symbol ] field The field name.
#
- # @return [ Hash ] count is a number of documents with the provided field. If there're none, then count is 0 and max, min, sum, avg are nil.
- # {
- # "count" => 2.0,
- # "max" => 1000.0,
- # "min" => 500.0,
- # "sum" => 1500.0,
- # "avg" => 750.0
- # }
+ # @return [ Hash ] count is a number of documents with the provided
+ # field. If there're none, then count is 0 and max, min, sum, avg
+ # are nil.
#
# @since 3.0.0
def aggregates(field)
result = collection.find.aggregate(pipeline(field), session: _session).to_a
if result.empty?