【问题标题】:How to read from List and Display in Jaspersoft iReport Designer 5.1 using MongoDB as a field如何使用 MongoDB 作为字段在 Jaspersoft iReport Designer 5.1 中读取列表和显示
【发布时间】:2013-07-05 04:04:52
【问题描述】:

我有一个 MondoDB 集合 'quotes' 和 lineItems 'list'.. 如下所示...

db.quotes.find();

> { "_id" : "51d31c4a0364a1b7f7cf45f7", 
    "accountName" : "NewAccountName", 
    "className" : "com.db.model.Quote",
    "cost" : "0",
    "lineItems" : [ { "lineNo" : 1, "product" : { "sku" : "MW216", "description" : "JBoss EAP", "cost" : "1043.5" }, "quotePrice" : "1230",     "quantity" : 4 },
                    { "lineNo" : 2, "product" : { "sku" : "MW217",  "description" : "JBoss EDS, "cost" : "15178.18"}, "quotePrice" : "0",   "quantity" : 3} ],
    "quoteNumber" : "22005",
    "shipping" : "GROUND"
}

我正在使用如图所示的 MongoDB 查询..

{
  'collectionName' : 'quotes',
  'findQuery' : {
      $where : "this.quoteNumber == $P!{QuoteNo}"
 }}

我想将每个 lineItem 显示为一行。

lineNo | sku   | Description       
1      | MW216 | JBoss EAP  
2      | MW217 | JBoss EDS  

如何在 JasperReports 中使用 iReport Designer 进行设计?

目前,当使用报告检查器中的“lineItems”字段并将其放置在报告中时,会将列表中的所有内容都显示为一个对象。我正在尝试读取列表中的每个字段并将其显示在按 lineItems 分组的报告中,如上所示。

任何帮助或线索将不胜感激,感谢您抽出时间帮助我。

【问题讨论】:

    标签: mongodb loops jasper-reports aggregation-framework


    【解决方案1】:

    首先你绝对不应该使用 $where - 而不是 $where : "this.quoteNumber == $P!{QuoteNo}" 你应该简单地使用 db.quotes.find({quoteNumber:YOURQUOTENO}) 这将在服务器上执行一个普通的 MongoDB 查询,而不是生成一个 Javascript shell 来执行 $where 语句。

    如果您想单独查看每个订单项,您可以像这样使用聚合框架$unwind

    db.quotes.aggregate({$unwind:"$lineItems"})

    这将为每个 lineItem 返回一个文档,因此如果您有五个文档,每个文档在数组中包含三个 lineItem,您将返回 15 个文档。

    【讨论】:

      猜你喜欢
      • 2012-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多