Page History
Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
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
Multiexcerpt include | ||||||
---|---|---|---|---|---|---|
|
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 |
---|---|
buildGroupString(out pipelineStructure: AggregateOderValue, | Parameters of the action script operation. |
create pipeline; |
|
set pipelineStructure.groupOperator = grouping; |
|
set pipelineStructure.groupOperator.sumOrderValue = sum; |
|
append pipelineStructure.classToExtendedJSON() to pipeline; |
|
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. |
If you provide an array of a result structure as an output for the adapter call, the xUML Runtime will map the results accordingly. |
Panel | ||
---|---|---|
| ||
|
Panel | ||
---|---|---|
|
Otp | ||
---|---|---|
|
|
Panel | ||
---|---|---|
| ||