Reputation: 1939
In Appengine (java), I'm able to list all the entities of my datastore using this code to delete them later. The problem is that I get lots of The kind "__XXX_Kind__" is reserved.
in the logs, so I'd like a way to retrieve all the entities under kinds which are not reserved.
Is this possible ?
do {
FetchOptions options = FetchOptions.Builder.withLimit(100);
if(cursor != null) {
options.startCursor(cursor);
}
QueryResultList<Entity> results = pq.asQueryResultList(options);
if(results.size() > 0) {
for (Entity result : results) {
try {
datastore.delete(result.getKey());
} catch (Exception e) {
log.warning(e.getMessage());
}
}
cursor = results.getCursor();
} else {
cursor = null;
}
} while(cursor != null);
Upvotes: 0
Views: 243
Reputation: 2207
You should be able to get all Kinds from the Metadata. Using GQL, you can run the below query to list all Kinds:
SELECT __key__ FROM __kind__ ORDER BY __key__
This will return all Kinds, including any System Kinds; kinds start with double underscores (e.g. __Stat_Kind__
).
While iterating over the results of the above query, just exclude the System Kinds and then run your delete for each kind to do the cleanup.
Depending on the API you are using, if it does not support GQL, use the equivalent Query Builder and run it.
Take a look at this AppEngine Datastore documentation
Upvotes: 1