I have a Model with a big blob property User.image Having this property in my model made my queries take too much time and go over the deadline so I decided to move that property into another model - UserData - who's parent is the User.
However, existing model instances that are already in the datastore still contain that image data even though the Model definition no longer contains that property.
Is there any, way to delete that data from the User instances?
Remove Property from an ObjectThe delete operator deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions.
You can't remove a property, unless you remove it permanently, for all cases. What you can do, however, is to create multiple classes, in a class hierarchy, where one class has the property and the other hasn't.
To remove a property from an object in TypeScript, mark the property as optional on the type and use the delete operator. You can only remove properties that have been marked optional from an object.
In JavaScript, there are 2 common ways to remove properties from an object. The first mutable approach is to use the delete object. property operator. The second approach, which is immutable since it doesn't modify the original object, is to invoke the object destructuring and spread syntax: const {property, ...
The answer to your question is documented here : https://developers.google.com/appengine/articles/update_schema
Copy/paste from the "Removing Deleted Properties from the Datastore" section :
If you remove a property from your model, you will find that existing entities still have the property. It will still be shown in the admin console and will still be present in the datastore. To really clean out the old data, you need to cycle through your entities and remove the data from each one.
- Make sure you have removed the properties from the model definition.
- If your model class inherits from db.Model, temporarily switch it to inherit from db.Expando. (db.Model instances can't be modified dynamically, which is what we need to do in the next step.)
- Cycle through existing entities (like described above). For each entity, use delattr to delete the obsolete property and then save the entity.
- If your model originally inherited from db.Model, don't forget to change it back after updating all the data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With