On this Page
Overview
The MongoDB Group Snap groups input documents by specified expressions. The Snap then generates one output document for each distinct grouping. Each of the output documents contains an _id field which contains the distinct group by key.
Input and Output
Expected input
- A document stream that contains information to construct a query condition or grouping condition.
Expected output
- A document stream that contains documents that are a result of the specified grouping or query condition.
Expected upstream Snaps
- A Snap that generates documents. For example, Mapper, JSON Generator, CSV Generator.
Expected downstream Snaps
- A Snap that accepts documents. For example, Mapper, Filter, and JSON Formatter.
Prerequisites
None.
Configuring Accounts
This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See MongoDB Account for information on setting up this type of account.
Configuring Views
Input | This Snap has at most one document input view. If the input view is defined, then values will be used to evaluate the expression in the conditions. |
---|---|
Output | This Snap has exactly one document output view. |
Error | This Snap has at most one document error view and produces zero or more documents in the view. |
Troubleshooting
None.
Limitations and Known Issues
None.
Modes
- Ultra pipelines: Works in Ultra Pipelines.
- Spark mode: Not supported in Spark mode.
Snap Settings
Label | Required. The name for the Snap. Modify this to be more specific, especially if there are more than one of the same Snap in the Pipeline. |
---|---|
Database name | The database that contains the documents. If you do not specify a database, then the Snap uses the MongoDB account database. Example: assets Default value: N/A |
Collection name | Required. The MongoDB collection name to execute the grouping. Example: users Default value: N/A |
Query Condition | An expression that represents the query parameter. If no query condition is defined, then MongoDB retrieves all the documents of the collection. When the expression evaluates to an object, only strict mode is supported. When the expression evaluates to a JSON string, both strict mode and mongo shell mode are supported. Click here for more information about MongoDB Extended JSON. Example: {num:1} Default value: N/A |
Group Condition | Required. The condition to group documents and create a single document for each distinct group. Read here for details on group conditions. Example: {"_id": "$Churn", "num_customer": {$sum: 1}, "total": {$sum: "$TotalCharges"}} Default value: N/A |
Sort Condition | The condition to order the documents in the result set. To use multiple sort orders, enter comma-separated sort conditions. Read here for details on sort conditions. Example: {age: -1} Default value: N/A |
Batch Size | Required. The number of documents to return in a batch. Click here for more details on how MongoDB batches documents. If n is the batch size, the Snap behaves as follows:
In MongoDB 3.4, the batch buffer size is 16MB. In previous versions, the batch buffer size is 4MB. The initial batch always returns a maximum of 101 documents. Click here for details. Example: 0 Default value: 0 |
Timezone Offset | The timezone offset to be applied to the time fields. By default, the Snap follows UTC (00:00 offset). |
Hours Offset | The number of hours to be offset. For example, if you specify a value of -2 in Hours Offset and 30 in Minutes Offset, then the timezone is offset by -2:30 hours. Example: -7 Default value: 0 |
Minutes Offset | The number of minutes to be offset. For example, if you specify a value of -2 in Hours Offset and 30 in Minutes Offset, then the timezone is offset by -2:30 hours. Example: 1 Default value: 0 |
Ignore empty result | If selected, no document is written to the output view when the group operation does not produce any result. If this property is not selected and the Pass through property is selected, the input document is passed through to the output view. Default value: Not selected |
Group result | Select to group results in one single field named result, instead of an array. Default value: Not selected |
Pass through | If selected, the input document is passed through to the output view under the key 'original'. Default value: Selected |
Page lookup error: page "Anaplan Read" not found. If you're experiencing issues please see our Troubleshooting Guide. | Page lookup error: page "Anaplan Read" not found. If you're experiencing issues please see our Troubleshooting Guide. |
Example
This Pipeline demonstrates how the MongoDB Group Snap helps you group the number of customers based on churn and the total customer count for a telecommunication company. For each group, the Pipeline returns the average monthly charges, and total charges for the Telco customer churn dataset.
Download the Pipeline.