Issue Description:If your MongoDB query returns a structure containing an array, you cannot dynamically pull individual items out of the array with the typical dot notation. | [toc] |
Take the following structure as an example:
db.greg1.save ( { 'name' : 'Rasheed Wallace', socialLinks : [ { 'id' : 'xyz', 'network' : 'Twitter' } ,{ 'id' : 'qrs', 'network' : 'Facebook'} ] } )
Resolution:
In mongoDB versions 2.2 and higher you can use the unwind command: http://docs.mongodb.org/manual/reference/aggregation/unwind/
To unwind the array from the sample above, try the following as your MongoDBQuery in iReport Designer:
{ runCommand : { aggregate : 'greg1' , pipeline : [ { $project : { name : 1, socialLinks : 1 }} ,{ $unwind : '$socialLinks'} ] } }
This runcommand returns three fields: name, socialLinks.network, socialLinks.id .
In mongoDB versions prior to 2.2 you can treat the array as a java.util.Collection object and pass it to a "net.sf.jasperreports.engine.data.JRMapCollectionDataSource" for use as a table or lists components dataset (other ideas like this here http://mdahlman.wordpress.com/2012/02/03/collections-in-reports-on-mongodb/)
Finally a more difficult option is to create your own map-reduce functions. For shell syntax see: http://docs.mongodb.org/manual/core/map-reduce/. We have samples for calling the map-reduce function within iReport Designer here: Jaspersoft MongoDB Query Language (Map Reduce) & (Map Reduce Sample Query)
Ref. Case #00035314
Recommended Comments
There are no comments to display.