system.mongodb.aggregate
This function is used in Python Scripting.
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 page for more details on scripting hints.
Description​
Returns a list of aggregate results.
Client Permission Restrictions​
This scripting function has no Client Permission 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 for all valid aggregate options. |
PyDictionary | collation | A PyDictionary of items to specify language-specific rules. See MongoDB documentation 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.
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​
# 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"])