英文:
I can't query GQL for 2 properties only wildcard is working
问题
我在Datastore中存储了comment
实体,并使用Datastore Viewer
查看存储的数据。
我可以执行以下查询:
select * from comment
select __key__ from comment
select Subject from comment
select Comment from comment
但是我无法执行以下查询:
select Subject, Comment from comment
// 错误:此查询的建议索引为:
// - kind: comment
// properties:
// - name: Comment
// - name: Subject
select __key__, Subject, Comment from comment
// 错误:不支持对属性 __key__ 进行投影
我找不到任何关于为什么出错的参考。这些错误信息并没有告诉我太多信息。
我没有为这些实体设置任何键或索引。
文档中提到了以下内容:
SELECT [DISTINCT] [* | <property list> | __key__]
[FROM <kind>]
[WHERE <condition> [AND <condition> ...]]
[ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
[LIMIT [<offset>,]<count>]
[OFFSET <offset>]
<property list> := <property> [, <property> ...]
<condition> := <property> {< | <= | > | >= | = | != } <value>
<condition> := <property> IN <list>
<condition> := ANCESTOR IS <entity or key>
<list> := (<value> [, <value> ...]])
Subject, Comment
是属性列表,是一个有效的查询。但实际上却不是。
我是用Go代码创建的实体。
英文:
I store comment
entity in Datastore and I use Datastore Viewer
to see stored data.
I can do following queries
select * from comment
select __key__ from comment
select Subject from comment
select Comment from comment
But I can't query
select Subject, Comment from comment
// Error: The suggested index for this query is:
// - kind: comment
// properties:
// - name: Comment
// - name: Subject
select __key__, Subject, Comment from comment
// Error: projections are not supported for the property: __key__
I can't find any reference why it is wrong. These errors does not tell me much.
I have not set any key or index for these entities.
Documentation tells following:
SELECT [DISTINCT] [* | <property list> | __key__]
[FROM <kind>]
[WHERE <condition> [AND <condition> ...]]
[ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
[LIMIT [<offset>,]<count>]
[OFFSET <offset>]
<property list> := <property> [, <property> ...]
<condition> := <property> {< | <= | > | >= | = | != } <value>
<condition> := <property> IN <list>
<condition> := ANCESTOR IS <entity or key>
<list> := (<value> [, <value> ...]])
Subject, Comment
- is property list and it valid query. But it is not.
I created entity from Go code.
答案1
得分: 3
投影查询有一些限制。在projection-doc中提到了"只有索引属性可以进行投影"
。
第一个错误消息明确显示了Subject, Comment
的组合索引尚不存在。您可以通过在项目根文件夹的index.yaml
中添加以下内容来手动创建索引:
- kind: comment
properties:
- name: Comment
- name: Subject
请参考index spec和projection-doc。
// 错误:不支持对属性进行投影:key
keys
实体是通过GetAll方法返回的。不要将它们放在投影中。
keys, err := q.GetAll(c, &people)
我还不能发布超过2个链接,所以请在数据存储参考中查找更多详细信息。
英文:
The projection queries come with some limitations. In the projection-doc is mentioned that "Only indexed properties can be projected"
.
The first error message shows exactly that the combined index of Subject, Comment
doesn't exist yet. You can create the index manually by adding
- kind: comment
properties:
- name: Comment
- name: Subject
to your index.yaml
in your project root folder. Please have a look at the index spec and projection-doc.
// Error: projections are not supported for the property: __key__
Entity keys
are returned by the GetAll method. Don't put them in your projection.
keys, err := q.GetAll(c, &people)
I can't post more than 2 links yet, so please look for more details in the datastore reference.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论