英文:
Google app engine: Golang datastore.GetAll() not working
问题
每周一次,一个cron作业在我的一个应用引擎项目中调用以下函数:
func cleanMealsFromDatabase(context appengine.Context) error {
query := datastore.NewQuery("Essen").Limit(1000).KeysOnly()
keys, err := query.GetAll(context, nil)
if err != nil {
return err
}
return datastore.DeleteMulti(context, keys)
}
我正在尝试批量删除一批数据存储实体。该函数被正确调用,但是query.GetAll(context, nil)
似乎总是返回一个错误。我做错了什么吗?
英文:
Once a week a cron job calls the following function in one of my app engine projects:
func cleanMealsFromDatabase(context appengine.Context) error {
query := datastore.NewQuery("Essen").Limit(1000).KeysOnly()
keys, err := query.GetAll(context, nil)
if err != nil {
return err
}
return datastore.DeleteMulti(context, keys)
}
I'm trying to batch delete a bunch of datastore entities. The function gets called correctly, but
query.GetAll(context, nil)
seems to always return an error. Am I doing something wrong?
答案1
得分: 0
好的,我现在知道出了什么问题。当我最终弄清楚如何在应用引擎中记录错误时,它显示的错误信息是:
API错误1(datastore_v3: BAD_REQUEST):无法在单个调用中写入超过500个实体
所以我所需要做的就是将Limit参数从1000更改为500,像这样:
query := datastore.NewQuery("Essen").Limit(500).KeysOnly()
现在它按预期工作了。
英文:
Okay, I now know what went wrong. When I finally figured out how to log an error in app engine, it said:
API error 1 (datastore_v3: BAD_REQUEST): cannot write more than 500 entities in a single call
So all I had to do, was to change the Limit parameter from 1000 to 500 like this:
query := datastore.NewQuery("Essen").Limit(500).KeysOnly()
Now it works like intended.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论