英文:
GAE datastore, GetMulti() with Projection?
问题
我的应用程序将许多不同类型的数据组合在一起,以便向用户生成报告。编译这份报告需要一些时间,用户可能希望在以后的某个日期查看这个快照,因此我将编译好的数据保存到数据存储中的一个单独的类型中。然后,可能在几个月后,用户会打开我保存的副本,但我想查询数据存储,只获取每个实体上可能已经更改的一个特定状态字段,以查看该实体是否在他们首次查看报告后发生了变化。
所以,我有所有我需要的键,我可以使用datastore.GetMulti()方法。但可能有成千上万个实体,每个实体都有许多字段,所以我想知道是否有一种更高效的方法来查询数据存储,只获取这一个字段,而不是整个数据集。类似于投影查询和GetMulti()的组合,但我在文档中找不到类似的内容,我是不是漏掉了什么?
英文:
My application puts together a grouping of many different Kinds of data for a report to the user, this report takes a while to compile and it is useful for the user to see this snapshot at a later date, so I save a copy of the data compiled into a separate Kind in the datastore. Then, possibly months later, the user pull up the copy that I saved, but I want to query the datastore for just one specific status field on each entity that may have changed since they originally ran the report, to see if that entity has changed since they first viewed the report.
So, I have all of the keys I need, I could do a datastore.GetMulti(). But there could be thousands of entities, and each one has many fields, so I was wondering if there was a more efficient method of querying the datastore to get just this one field, instead of the entire set of data. Something like a combination of a projection query and a GetMulti(), but I can't find anything like that in the docs, am I missing something?
答案1
得分: 1
投影查询不一定只针对单个实体。您可以使用投影查询来实现这一点。在您的情况下,可以这样做:
q := datastore.NewQuery("EntityKindYouDefinedName").Project("status_property")
有关如何处理此投影查询结果的更多信息,请参阅文档。
英文:
Projection queries don't have to be only on a single entity. You can do exactly this with a projection query. In your case, something like this:
q := datastore.NewQuery("EntityKindYouDefinedName").Project("status_property")
See the doc for more information on how to process the results of this projection query.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论