英文:
Query entities by specifying a list of values in GAE Datastore
问题
在我的Datastore中,我想通过指定相同属性的值作为过滤器来查询一些实体。
例如,我有一个名为Foo的实体,定义如下:
type Foo struct {
Id int64
Name string
CreatorId int64
}
我想检索所有具有1、5、23作为CreatorId的Foo实体。所以我定义了以下查询:
q := datastore.NewQuery("Foo").Filter("CreatorId =", 1).Filter("CreatorId =", 5).Filter("CreatorId =", 23)
但是没有获取到任何实体。我查阅了文档(https://developers.google.com/appengine/docs/go/datastore/reference),但没有解释如何实现这种类型的查询。
非常感谢您的帮助。
英文:
In my Datastore, I would like to query some entities by specifying as Filter the values of the same property.
For instance I have the Entity named Foo defined as follows:
<code>type Foo struct {
Id int64
Name string
CreatorId int64
}
</code>
And I want to retrieve all the Foo entities which have 1, 5, 23 as CreatorId. So I define the following query:
<code>q := datastore.NewQuery("Foo").Filter("CreatorId =", 1).Filter("CreatorId =", 5).Filter("CreatorId =", 23)</code>
But zero entity has been fetched. I looked into the documentation (https://developers.google.com/appengine/docs/go/datastore/reference) but it is not explained how to achieve this kind of query.
Some help will be greatly appreciated.
答案1
得分: 1
Java和Python允许你在集合中运行一个值的查询(IN查询)。然而,在底层,这个查询被执行为一系列的EQUALS查询。从性能上来说,与在循环中运行常规的EQUALS查询相比,代码稍微少了一些,但没有任何区别。
英文:
Java and Python allow you to run a query for a value in a collection (IN query). Under the surface, however, this query is executed as a series of EQUALS queries. It's a little less code, but no difference performance-wise, than to run regular EQUALS query in a loop.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论