Search code examples
pythongoogle-app-enginegoogle-cloud-datastore

Update one property of an entity in google cloud datastore python


How do I update only one property of an entity in the google cloud datastore, without remove all other properties?

key = client.key('employee', ID)
employee_to_deactivate = datastore.Entity(key)
employee_to_deactivate.update({
    'active':False,
})

this updates the active property to False, but removes all the other properties.


Solution

  • You cannot update specific properties of an entity. All writes (inserts, updates) must include all properties that should be persisted. Whenever you need to do an update, you need to first retrieve the existing entity as a whole, then update one or more properties by setting new values and update the entity.