How to delete all datastore in Google App Engine?

后端 未结 29 1805
夕颜
夕颜 2020-11-28 01:17

Does anyone know how to delete all datastore in Google App Engine?

29条回答
  •  爱一瞬间的悲伤
    2020-11-28 01:56

    The fastest and efficient way to handle bulk delete on Datastore is by using the new mapper API announced on the latest Google I/O.

    If your language of choice is Python, you just have to register your mapper in a mapreduce.yaml file and define a function like this:

    from mapreduce import operation as op
    def process(entity):
     yield op.db.Delete(entity)
    

    On Java you should have a look to this article that suggests a function like this:

    @Override
    public void map(Key key, Entity value, Context context) {
        log.info("Adding key to deletion pool: " + key);
        DatastoreMutationPool mutationPool = this.getAppEngineContext(context)
                .getMutationPool();
        mutationPool.delete(value.getKey());
    }
    

    EDIT:
    Since SDK 1.3.8, there's a Datastore admin feature for this purpose

提交回复
热议问题