Skip to main content
Version: 8.1

system.mongodb.updateOne

New in 8.1.28

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 page for more details on scripting hints.

Description​

Updates a document in the collection that matches the filter.

Client Permission Restrictions​

This scripting function has no Client Permission restrictions.

Syntax​

system.mongodb.updateOne(connector, collection, filter, updates, [options])

Parameters​

TypeParameterDescription
StringconnectorThe name of connector (case-insensitive).
StringcollectionThe name of collection (case-sensitive).
PyDictionaryfilterA PyDictionary for specifying matching key value pair criteria when querying a collection.
PyDictionary / List[PyDictionary]updatesChanges to apply to specific document fields. Also supports aggregation pipeline for update operations See MongoDB documentation for all valid update operators.
PyDictionaryoptionsA PyDictionary for including additional update configurations. [optional].

Returns​

PyDictionary result - Result of update action formatted as a PyDictionary with keys ‘acknowledged’, ‘modifiedCount’, ‘matchedCount’, and ‘upsertedId’.

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​

Example #1
# Import required BSON types.
from system.mongodb.types import ObjectId

# Specify unique field values to locate specific document. Here we are specifying the known _id of the document.
filter = {"_id": ObjectId("63fe3941519feb58abb3cda1")}

# Specify document fields to update for found BSON document(s). 'accounts' is an existing field on the document.
updates = [
{"$set":
{
"accounts": [415623, 983462]
}
}
]

# Apply parameters for function call.
print system.mongodb.updateOne("MongoDB", "customers", filter, updates)

Keywords​

system mongodb updateOne, mongodb.updateOne