【问题标题】:MongoID 5 Aggregations: NoMethodError: undefined method `[]' for AggregationMongoID 5 聚合:NoMethodError:未定义的方法 `[]' 用于聚合
【发布时间】:2016-09-19 08:18:33
【问题描述】:

升级到 MongoID 5 后,我收到此错误: NoMethodError: #

的未定义方法“[]”

代码如下:

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

因此,聚合已经使用数组作为参数。

【问题讨论】:

    标签: mongoid aggregate aggregate-functions mongoid5


    【解决方案1】:

    检查结果包含什么后,我意识到它没有响应[]。但是,它确实响应 .first

    代码看起来像

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

    【讨论】:

      猜你喜欢
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 2015-01-21
      • 1970-01-01
      相关资源
      最近更新 更多