--- title: "system.mongodb.aggregate" description: "Returns a list of aggregate results." --- # system.mongodb.aggregate > Returns a list of aggregate results. This function is used in **Python Scripting**. :::note Project Library scripts will not provide hints for MongoDB system functions unless the Script Hint Scope is set to **Gateway**. See the [Scripting in Ignition](platform\scripting\scripting-in-ignition\scripting-in-ignition.md#system-functions-hints-and-autocomplete) page for more details on scripting hints. ::: ## Description ## Client Permission Restrictions This scripting function has no [Client Permission](../../../ignition-modules/vision/vision-project-properties/vision-project-properties.md#vision-permissions-properties) restrictions. ## Syntax `system.mongodb.aggregate(connector, collection, aggregate, [collation])` ### Parameters Type | Parameter | Description ------- | ------- | ------ String| `connector` | The name of connector (case-insensitive). String| `collection` | The name of collection (case-sensitive). List[PyDictionary]| `aggregate` | A list of PyDictionaries to specify an aggregate pipeline. [See MongoDB documentation](https://www.mongodb.com/docs/manual/aggregation/) for all valid aggregate options. PyDictionary| `collation` | A PyDictionary of items to specify language-specific rules. [See MongoDB documentation](https://www.mongodb.com/docs/manual/reference/collation/) for all valid collation values. [optional] ### Returns **List[PyDictionary]** result - A list of PyDictionary results containing aggregation results. ### Scope Gateway, Perspective Session ## Importing Classes You can import classes from system.mongodb.types like you would other Python classes: #### Example ``` from system.mongodb.types import ObjectId newObjectId = ObjectId.get() ``` You can also iterate those system.mongodb.types packages to see all available classes: #### Example ``` for d in dir(system.mongodb.types): print d ``` ### API Docs MongoDB-specific data types come from the org.bson.types package of the Mongo Java Driver API. The library of classes available for import can be accessed at this link: [Mongo Java Driver 3.6.0 API Docs for Package org.bson.types](https://mongodb.github.io/mongo-java-driver/3.6/javadoc/org/bson/types/package-summary.html). ## Types References The following values can be referenced for the types parameter at system.mongodb.types: ``` Binary Code CodeWScope CodeWithScope Decimal128 INSTANCE MaxKey MinKey ObjectId Symbol Timestamp ``` ## Code Examples ```python title="Example #1" # Retrieve a both a connector name to query from. connector = system.mongodb.listConnectorInfo()[0]['name'] # Specify aggregate that will find the sum of all key value pairs named transaction_count. aggregate = [ {"$group": { "_id": '', "OverallTransactionTotal":{"$sum": "$transaction_count"} } } ] # Apply all parameters for our function call. result = system.mongodb.aggregate(connector, "transactions", aggregate) # Print the result. Here it is expected that the aggregate parameter's key OverallTransactionTotal can be extracted. print "Overall Transaction Total: " + str(result[0]["OverallTransactionTotal"]) ```