Reputation: 1
I have a MondoDB Collection 'quotes' with lineItems 'list'.. as shown below...
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"
}
I am using the MongoDB Query as shown..
{
'collectionName' : 'quotes',
'findQuery' : {
$where : "this.quoteNumber == $P!{QuoteNo}"
}}
I would like to Display each lineItem as one row.
lineNo | sku | Description
1 | MW216 | JBoss EAP
2 | MW217 | JBoss EDS
How to design this in the with JasperReports using iReport Designer?
Currently when using the 'lineItems' field from the Report Inspector and placing that in the Report shows every thing that is there in the List as one object. I am trying to read each field in the list and display it in the report grouping by lineItems as shown above.
Any help or clues will be appreciated and Thanks for your time in helping me out.
Upvotes: 0
Views: 1408
Reputation: 42352
First you should absolutely not be using $where - instead of $where : "this.quoteNumber == $P!{QuoteNo}"
you should simply use db.quotes.find({quoteNumber:YOURQUOTENO})
this will execute a normal MongoDB query on the server, rather than spawning a Javascript shell to execute $where
statement.
If you want to see each line item separate you want to use aggregation framework $unwind
like this:
db.quotes.aggregate({$unwind:"$lineItems"})
This will return one document per each lineItem so if you have five documents with each of them having three lineItems in the array you would get back 15 documents.
Upvotes: 1