Aggregating Data
This page explains the MongoDB Adapter in Bridge context. If you were looking for the same information regarding the PAS Designer, refer to MongoDB Adapter in the Designer guide.
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 two stages:
- a
$match
stage that selects documents from the database - a
$group
stage that groups documents and summarizes a value
Example File (Builder project Add-ons/MongoDB):
<your example path>\Add-ons\MongoDB\uml\simpleMongoDbAccess.xml |
Creating an Aggregation Pipeline
Aggregation stages can be reflected in MagicDraw using the following class construct:
The displayed class diagram defines aggregations stages to aggregate property orderVolume per country for all or a selected country.
Class | Description |
---|---|
1 | Stage $match Describes a match stage.
|
2 | Stage $group Describes a group stage.
|
3 | Sum Operator
|
You can add other stages to this diagram using the same pattern.
Aggregating Data
The activity diagram below shows how to build the pipeline and trigger the aggregation.
Step | Description |
---|---|
1 | Build the Match Stage
|
2 | Build the Group Stage
|
As a result, you will get a JSON document orderVolumePerCountry that contains the following order value aggregation:
{
"orderVolume": [
{
"_id": "USA",
"sumOrderVolume": 1098.0
},
{
"_id": "CAN",
"sumOrderVolume": 180.0
}
]
}
Related Documentation: