Imported APEs
For users who wish to write their own MongoDB aggregation pipeline expressions (APE), Logi Report allows them to put the expressions into JSON files (.json) and import the files into a catalog via the specified MongoDB connection. Logi Report can then load data from the MongoDB database by the aggregation pipeline expressions in the imported JSON files.
At present each JSON file can contain only one aggregation pipeline expression. For details about the expression definition, refer to https://docs.mongodb.com/manual/core/aggregation-pipeline/.
The imported JSON files can work similarly as imported SQLs, for example, you can use imported APEs to build queries and business views, and create page reports directly.
This topic includes the following sections:
- Creating the Aggregation Pipeline Expressions
- Importing JSON Files into a Catalog
- Updating the JSON Files
Creating the Aggregation Pipeline Expressions
When you write aggregation pipeline expressions, you need to make sure they follow JSON format. The key and value pairs in an aggregation pipeline expression should be marked with double quotation marks (double quotation marks are not needed for a value whose data type is not String), and enclosed in a pair of square brackets. Moreover, when the data in the MongoDB database is of hierarchical structure, in order to get all detail data in the MongoDB databases, it is suggested that you add $unwind in the expression, then a tabular with all data records can be returned; otherwise a hierarchical structure with partial data records will be returned.
The following is an example:
[ {"$match" : { "CUSTOMERID" : { "$gt" : 10}}}, { "$project" : { "CUSTOMERNAME" : 1 , "COUNTRY" : 1 , "CUSTOMERID" : 1}}, { "$sort" : { "COUNTRY" : 1}} ]
In an aggregation pipeline expression, you can use parameters and constant level formulas predefined in the catalog data source in which the MongoDB connection is created in the format @FieldName or ?FieldName to calculate your data. For example, if you need to get different result sets at runtime, you can reference parameters in the $match stage of the expression to dynamically filter the data. In the above example, if you want to use a parameter to return a result set in which the customer ID is greater than the parameter, then the $match stage would be like this:
{"$match" : { "CUSTOMERID" : { "$gt" : @pID}}}
Where, pID is a parameter and fID is a constant level formula created in the catalog.
Besides using parameters, you can also use the special field User Name as @username in the $match stage of the aggregation pipeline expressions to filter data dynamically.
Note: When the Scope of All Values property of a parameter is set to All Values in Database, the parameter cannot be used in aggregation pipeline expressions.
Importing APEs from JSON Files into a Catalog
After you have set up the MongoDB connection and saved aggregation pipeline expressions in JSON files, you can import them into the Logi Report catalog as follows:
- In the Catalog Manager resource tree, right-click the MongoDB connection and select Add APE on the shortcut menu.
- In the Select a JSON File dialog, browse to the JSON file and select Open.
- In the Enter Aggregation Pipeline Expression Information dialog, type a name for the JSON file in the Expression Name text box, select the database and collection of the MongoDB database from which to get data in accordance with the aggregation pipeline expression in the selected JSON file. Select OK.
The JSON file is then added in the Imported APEs node in the catalog resource tree. You can right-click it and select Show APE from the shortcut menu to view the aggregation pipeline expression in the JSON file if you want. The format of the JSON file, such as comments, are maintained when it is added into the Logi Report catalog.
When you import a JSON file via the Data screen of the report wizard, you should also specify the MongoDB connection based on which to execute the aggregation pipeline expression in the selected JSON file from the Connection drop-down list.
Updating the JSON Files
If you make any change to the aggregation pipeline expression in an JSON file, you need to update the JSON file in the Logi Report catalog so that reports built based on the aggregation pipeline expression can work properly.
- From the Imported APEs node in the catalog resource tree, select the JSON file, right-click it and select Update from the shortcut menu.
- In the Select a JSON File dialog, select the JSON file you want to update, then select Open.
- In the Enter Aggregation Pipeline Expression Information dialog, select the database and collection of the MongoDB database from which to get data in accordance with the aggregation pipeline expression in the selected JSON file.
- Select OK to update the JSON file.