How to update single property of multiple entities in specific kind of datastore?

960 views Asked by At

I want to update one property of each entity present in one particular kind of my datastore. In traditional sql, we do something like this as -

update <tablename> set <property> = <value>; {where clause is optional}

Now, how can I do same thing for datastore using golang code?

1

There are 1 answers

0
Zachary Raineri On

In Datastore you can't perform an update like that without retrieving the entities. You have to pull all entities in that kind, update the property on each, and re-upsert the now updated entities (preferably in a batch).

Go Datastore Queries: https://cloud.google.com/datastore/docs/concepts/queries#datastore-datastore-basic-query-go

Go Update Entities: https://cloud.google.com/datastore/docs/concepts/entities#datastore-datastore-update-go

Go Batch Upsert: https://cloud.google.com/datastore/docs/concepts/entities#datastore-datastore-batch-upsert-go