Skip to main content

UpdateEntity

Updates existing Entity objects that satisfy the specified constraints.

Parameters​

ref and constraints are optional and are intersected when both are present. with_class further narrows the selection. Scope warning: omitting all selectors targets every object in public entity classes. Always supply selectors for a scoped mutation.

Parameter

JSON type

Behavior

constraints

array expression

Optional. No property filter; the command-specific selector requirement still applies. Filters existing objects using the constraints expression language. When ref is supplied it filters that referenced set.

properties

object mapping property names to values

Optional. When omitted, existing user properties are unchanged except for keys listed in remove_props. Stores booleans, numbers, strings, supported arrays, or single-key _date, _blob, and _json wrappers. Bare null is rejected; property names and wrapped values are validated. See the properties reference for nested value rules. Replaces supplied property values without replacing the whole property map.

ref

integer, 1 through 100000

Optional. Select using the other supplied selectors; see the selection rule above. Uses an earlier compatible Entity reference in this transaction; forward references, wrong types, and undeclared references are rejected.

remove_props

array of strings

Optional. When omitted, no properties are removed. Removes named properties from selected objects; missing keys have no effect. A value also supplied in properties is stored after removal.

with_class

nonempty string, not starting with underscore

Optional. No additional class restriction; without a reference, all public classes are eligible. Restricts the mutation to this entity class, including when ref is supplied.

Details​

If the ref parameter is used, with_class and constraints will act as additional filters on the referenced result set. If the ref parameter is specified, it must refer to the results of an earlier AddEntity or FindEntity.

For more complex searches for object to update, a Find command must be used first within the transaction.

Response and errors​

An authenticated session with the objects update permission is required.

The response is an object under UpdateEntity with integer status and, on success, integer count. Status 0 means the mutation completed; count is the number of selected objects affected, including zero when none match. No output blobs are returned.

Invalid field types, missing required fields, malformed expressions, and invalid references fail validation. Execution failures include a nonzero status and an info message; inspect the transaction response before assuming a mutation succeeded.

Examples​

Find the entity of class “Person” with a particular “email” property, and remove the “last_connected” property:

[{
"UpdateEntity": {
"with_class": "Person",
"constraints": ["$email", "==", "jane.doe@xyz.com"],
"remove_props": ["last_connected"]
}
}]

Successful response:

[{
"UpdateEntity": {
"count": 1,
"status": 0
}
}]

Find the entity of class “Person” with a specific “email” property, and change/add two new properties:

[{
"UpdateEntity": {
"with_class": "Person",
"constraints": ["$email", "==", "jane.doe@xyz.com"],
"properties": {
"type": "friend",
"year_met": 2018
}
}
}]

Successful response:

[{
"UpdateEntity": {
"count": 1,
"status": 0
}
}]

Update all entities of the class “Person” that have the property “age” greater than 18 and that have a connection to an entity of the class “Nation”, setting their property “vaccine” to “eligible”:

[{
"FindEntity": {
"with_class": "Nation",
"_ref": 1,
"constraints": ["$name", "==", "India"]
}
}, {
"FindEntity": {
"_ref": 2,
"with_class": "Person",
"constraints": ["$age", ">=", 18],
"is_connected_to": {
"ref": 1
}
}
}, {
"UpdateEntity": {
"ref": 2,
"properties": {
"vaccine": "eligible"
}
}
}]

Successful response:

[{
"FindEntity": {
"returned": 0,
"status": 0
}
}, {
"FindEntity": {
"returned": 0,
"status": 0
}
}, {
"UpdateEntity": {
"count": 1,
"status": 0
}
}]