问题
I installed Birt 4.3 (latest) as Eclipse plugin. JDBC as data source works perfectly for me. I define a param in query. I can define a param in data set via Report Design and link it to a report param.
But I have multiple issues with MongoDB
1) When I open "edit data set" dialog I cannot find the menu "Parameters" in left side. I only see
Data Source
Query
Output Columns
Computed Columns
Filters
properties Binding
Setting
Review Results
No Parameter any more. I can see it in JDBC not in MongoDB Could anyone please how to define a parameter in data set while Data source is MongoDB? How to link the param to the param of report?
2) In MongoDB (Birt) how to define a parameter in the expression of "Run Database Command" or in query In JDBC we can use "?" as a param holder like
select * where id=?
param will replace "?"
For MongoDB
{
runCommand : {
aggregate : COLLECTION_NAME,
.....
}
}
COLLECTION_NAME
is vary. How can I represent it?
Any help will be appreciated.
Thanks
回答1:
MongoDB expression syntax itself does not support parameters, thus the MongoDB ODA connector does not support data set parameters directly. You can use BIRT scripting to reference a BIRT report parameter and change the runtime value of the "Command expression" data set property.
You can identify the system connection when you make a MongoDB data set using Eclipse. This is in the MongoDB Collection area of the data set dialog.
Check http://www.eclipse.org/forums/index.php/t/628348/ for more information.
EXAMPLE
You can use script to set the query using a beforeOpen script in the dataset such as:
this.queryText ='{ "findQueryExpr" : "{ pop: { $gte: 20000 } }" , "operationType" : "FIND" , "collectionName" : "zipcode" , "selectedFields" : [ "_id" , "city", "pop"]}'
The fields and collection name need to match the pre-configured dataset.
Replace the 20000 with your parameter value. For example, using a parameter named "Population" which takes an integer, you can update your query at run-time with the following script:
this.queryText ='{ "findQueryExpr" : "{ pop: { $gte: '+params["Population"].value+' } }" , "operationType" : "FIND" , "collectionName" : "zipcode" , "selectedFields" : [ "_id" , "city", "pop"]}'
来源:https://stackoverflow.com/questions/25024375/birt-mongodb-param