Aggregating Data
Using a MongoDB aggregation pipeline, you can select and aggregate documents. A pipeline is an array of one or multiple stages that will be processed one after the other. Refer to the MongoDB Manual for more information on aggregation and pipelines.
The example below shows a simple aggregation pipeline that consists of one single stage: a $group
stage that groups documents and summarizes values
MongoDBAdapter_CustomerData_Example
Click here to download a simple example model that shows the usage of the MongoDB adapter in Scheer PAS Designer.
Creating an Aggregation Pipeline
Aggregation stages can be reflected in the Designer using the following class construct:
The displayed class diagram defines aggregations stages to aggregate property orderValue per country for all or a selected country.
Class | Description |
---|---|
(1) | Stage $group Describes a group stage.
|
(2) | Sum Operator
|
You can add other stages (e.g. a $match stage) to this structure using the same pattern.
Aggregating Data
Building the Aggregation Pipeline
The action script below shows how to build the pipeline.
Action Script | Explanation |
---|---|
CODE
| Parameters of the action script operation. |
CODE
|
|
CODE
|
|
CODE
|
|
CODE
|
|
The resulting aggregation pipeline will look like
{ "$group" : { "_id" : "$address.country", "sumOrderValue" : { "$sum" : "$orderValue" } } }
Aggregation Result
As a result of the aggregation, you will get a JSON document that contains the following order value aggregation:
{
"orderVolume": [
{
"_id": "USA",
"sumOrderVolume": 1098.0
},
{
"_id": "CA",
"sumOrderVolume": 180.0
}
]
}
If you provide an array of a result structure as an output for the adapter call, the xUML Runtime will map the results accordingly:
Related Documentation: