system.mongodb.insertOne
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β
Inserts a single PyDictionary into a specified collection.
Client Permission Restrictionsβ
This scripting function has no Client Permission restrictions.
Syntaxβ
system.mongodb.insertOne(connector, collection, document, [options])
Parametersβ
| Type | Parameter | Description |
|---|---|---|
| String | connector | The name of connector (case-insensitive). |
| String | collection | The name of collection (case-sensitive). |
| PyDictionary | document | A PyDictionary of specified fields that will represent a record being added to the collection. See MongoDB documentation for more details about documents. |
| PyDictionary | options | A PyDictionary for including additional insert configurations. [optional]. |
Returnsβ
PyObject objectId - Key of inserted document. This will usually be BSON document ObjectId, unless a different key type is specified.
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β
# Import required BSON types.
from system.mongodb.types import ObjectId
from system.mongodb.types import Timestamp
# Specify required document fields in a PyDictionary format for BSON document.
document = {
"_id": ObjectId(),
"transaction_count": 0,
"bucket_start_date": Timestamp(),
"bucket_end_date": '',
"transactions": []
}
# Apply parameters for function call.
print system.mongodb.insertOne("MongoDB", "transactions", document)