jasper report with mongodb in aggregation framewor

2019-04-13 16:10发布

问题:

I have a collection named Stock_Data_Revise_Nyse which has some relevant data and i am making reports using jasper ireporter but when i execute this given query it only returns me value field with appropriate value and rest _id.Date,_id.Stock returns null.

This query is running perfectly fine in Mongo Shell.

noticed:- If i use single group by then aggregation works fine in Jasper but when i use double group by like i have used here it returns null for that field.

I have searched many forums but hardly found any answer.

Any Kind Of Help Would Be Appreciated.

{ runCommand: {
    aggregate : "Stock_Data_Revise_Nyse",
    pipeline : [
        {$project:{Symbol_1:1,Name:1,Change:1,Date:{$substr:["$UTC_Timestmp",0,10]}}},
        {$match:{"Date":"16-01-2013"}},
        {$group:{
            _id:{Date:"$Date",Stock:"$Symbol_1"},
            value:{$sum:"$Change"}
        }},
        {$sort:{"value":-1}},
        {$limit:5}
    ]
}}

回答1:

This is because you're using an old version of MongoDB Connector (v0.5.0, which is the only version available on MongoDB Connector download page).

Download JasperSoft Studio v2.0.1 or later, then use the included file plugins/com.jaspersoft.studio.data.mongodb_2.0.1.jar as your dependency to replace the old MongoDB Connector v0.5.0.

You can also get this artifact using Maven (we Bippo/Soluvas are only providing the service to host commonly needed files in a Maven repository):

<dependencies>
    <dependency>
        <groupId>com.jaspersoft</groupId>
        <artifactId>com.jaspersoft.studio.data.mongodb</artifactId>
        <version>2.0.1</version>
    </dependency>
</dependencies>
...
<repositories>
    <repository>
        <id>bippo-nexus-public</id>
        <url>http://nexus.bippo.co.id/nexus/content/groups/public/</url>
    </repository>
</repositories>