google app引擎数据存储区使用“ in”运算符进行查询
Using Query in App Engine Datastore, how do I specify to fetch keys that match a property with variable values?
var Person struct {
name string
department string
}
//Query
q := datastore.NewQuery("Person").Filter("department = ", "department1").KeysOnly()
In the above query, instead of "=" operator, I want "IN" operator to specify more than 1 department value i.e fetch all person keys who belong to department1, department2, department3 etc.
Is this possible with 1 Query? Or do I need to make 1 query for each department?
在App Engine数据存储区中使用查询,如何指定获取与具有可变值的属性匹配的键? p>
var Person结构{
名称字符串
部门字符串
}
// Query
q:= datastore.NewQuery(“ Person”)。Filter(“ department =“,” department1“)。KeysOnly()
code> pre>
在上面的查询中,我要使用” =“ strong>运算符 “ IN”运算符可指定多个1部门值,即获取属于部门1,部门2,部门3等的所有人员密钥。 p>
使用1个查询是否可行? 还是我需要为每个部门查询1个? p>
div>
Other runtimes allow "IN" operator for datastore queries. It is, however, just a convenience: under the hood, the datastore makes individual queries for each element in the list.
If you have a relatively small number of entities, it may be more efficient to retrieve all of them and then filter the results based on the "department" property, rather than issues N queries to search for N possible departments.