0

Is there a way to delete a property from all entities in Google Datastore using Java? I want it to no longer be visible in the Google Cloud Console.

I tried setting the property to null in all entities but that did not work. It still shows up in the GCC when looking at the list of entities. It's just every single entry is null.

How can I completely remove this property from my entity?

EDIT: Here is what it looks like in GCC. I want to just remove this property completely:

enter image description here

Micro
  • 10,303
  • 14
  • 82
  • 120

1 Answers1

0

It's not possible to bulk update entities with a single query or command. You will have to read each entity individually, remove the field you no longer want (in memory, after you have read the entity), then update the entity again with the new set of properties that does not include the one you want removed.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • So how can I do that in Java? I tried to read each entity, set the property to `null` and then save those entities back to the datastore. But the property still exists and it's value is show as `null` in GCC. I can't do something like set it as `undefined` as one could in javascript for example. Is there a way for me to read and save the entity back to the datastore with that one property as something like not-set or undefined? – Micro Dec 26 '21 at 22:54
  • I added an edit to my question. – Micro Dec 26 '21 at 23:47
  • 1
    Don't use null. Null is valid value, and you don't want to put a value there. Put only the properties you want into a Map, and feed that into the new entity. It's hard to see where you might need a course correct because you've shown no code. The steps are 1) read the entity, 2) copy only the properties you want from that into a new entity, 2) write the new entity in place of the first. Or use an entity builder loaded up with copied properties and literally `remove()` the ones you want out of it. – Doug Stevenson Dec 27 '21 at 00:33