【发布时间】: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?
【问题讨论】: