MongoID 5 Aggregations: NoMethodError: undefined method `[]' for Aggregation

256 Views Asked by At

After upgrading to MongoID 5 I'm getting this error: NoMethodError: undefined method `[]' for #

The code looks like:

result = ::Presentation::Interaction.collection.aggregate(
  [
    user_match_criterias_live(conference),
    ::Presentation::ReportGenerator::DELCOUNTRY_AGGREGATION
  ]
)
return 0 if (result.count < 1)
return result[0]["total"]

So, aggregate is already using an array as an argument.

1

There are 1 best solutions below

0
hcarreras On BEST ANSWER

After checking what result contains, I realised that it doesn't respond to []. However, it does respond to .first

The code would look like

result = ::Presentation::Interaction.collection.aggregate(
  [
    user_match_criterias_live(conference),
    ::Presentation::ReportGenerator::DELCOUNTRY_AGGREGATION
  ]
)
return 0 if (result.count < 1)
return result.first["total"]