【问题标题】:Using ObjectId parameters in Pentaho reporting against MongoDB在针对 MongoDB 的 Pentaho 报告中使用 ObjectId 参数
【发布时间】:2013-12-12 15:33:39
【问题描述】:

我正在使用 Pentaho 对 MongoDB 进行报告。在转换中,我的查询是一个聚合管道,如下所示:

[   
{$match: {billing_cycle_id: "${billing_cycle}"} },
{
    $project : {
        account_id : 1,
        age_120.cents : 1,
        age_60.cents : 1,
        age_30.cents: 1,
        balance.cents: 1,
        billing_cycle_id : 1,
        transaction_line_items : 1
    }
},
{$unwind : "$transaction_line_items"}
]

${billing_cycle} 的默认值为 5162f1c0b7228a2793000011

下面是 Pentaho 日志中的查询:

2013/12/12 09:57:12 - MongoDB Input.0 - Query pulled data from: [   
2013/12/12 09:57:12 - MongoDB Input.0 -     {$match: {billing_cycle_id: "5162f1c0b7228a2793000011"} },
2013/12/12 09:57:12 - MongoDB Input.0 -     {
2013/12/12 09:57:12 - MongoDB Input.0 -         $project : {
2013/12/12 09:57:12 - MongoDB Input.0 -             account_id : 1,
2013/12/12 09:57:12 - MongoDB Input.0 -             age_120.cents : 1,
2013/12/12 09:57:12 - MongoDB Input.0 -             age_60.cents : 1,
2013/12/12 09:57:12 - MongoDB Input.0 -             age_30.cents: 1,
2013/12/12 09:57:12 - MongoDB Input.0 -             balance.cents: 1,
2013/12/12 09:57:12 - MongoDB Input.0 -             billing_cycle_id : 1,
2013/12/12 09:57:12 - MongoDB Input.0 -             transaction_line_items : 1
2013/12/12 09:57:12 - MongoDB Input.0 -         }
2013/12/12 09:57:12 - MongoDB Input.0 -     },
2013/12/12 09:57:12 - MongoDB Input.0 -     {$unwind : "$transaction_line_items"}
2013/12/12 09:57:12 - MongoDB Input.0 - ]

我猜问题是这不会返回任何数据,因为 billing_cycle_id 是一个 ObjectId 但是当我将查询更改为

[   
{$match: {billing_cycle_id: ObjectId("${billing_cycle}")} },
{
    $project : {
        account_id : 1,
        age_120.cents : 1,
        age_60.cents : 1,
        age_30.cents: 1,
        balance.cents: 1,
        billing_cycle_id : 1,
        transaction_line_items : 1
    }
},
{$unwind : "$transaction_line_items"}
]

查询时出现 Pentaho 错误。如何在参数中成功使用 ObjectId?

【问题讨论】:

    标签: mongodb reporting pentaho


    【解决方案1】:

    当我想在 mongodb 输入查询步骤中传递 id 比较时,我遇到了同样的问题。之后我找到了解决方案,我在 pentaho 查询中比较了 mongoid,如下所示

    { "_id" :{'$oid':"52a5f2aee4b08d0d5ca1f3f5"}}
    

    我认为在您的情况下,您应该遵循以下方式

    [   
         {$match: {billing_cycle_id: {'$oid':"${billing_cycle}"}}},
           {
            $project : {
            account_id : 1,
            age_120.cents : 1,
            age_60.cents : 1,
            age_30.cents: 1,
            balance.cents: 1,
            billing_cycle_id : 1,
            transaction_line_items : 1
           }
        },
         {$unwind : "$transaction_line_items"}
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      相关资源
      最近更新 更多