Search code examples
javagoogle-app-enginetransactionsgoogle-cloud-datastore

Deleting entities from Google App Engine with dash in their name


I need delete from my DB all entities, that contain the "-" sign in the "name" prop.

What do I need to make a query?


Solution

  • You can't do that in the GAE datastore with only one query, because the datastore does not support "contains" queries. Therefore, you have two options:

    1. Select all entities and iterate over the result set, checking if the name contains a "-".
    2. Add a new property, e.g. "nameContainsDash" to your entity and query all entities that have this property set to true. This property is updated every time the name is updated.
    ...
    
    public void setName(String name) {
        this.name = name;
        nameContainsDash = name.contains("-");
    }
    
    public boolean isNameContainsDash() {
        return nameContainsDash;
    }
    
    ...
    

    Of course, the second option might require data migration, since the property will be null for existing entities.