我正在尝试从数据存储中获取所有数据实体。当我遇到谷歌文档时,我发现了类似的内容查询投影 (链接到文档 https://cloud.google.com/datastore/docs/concepts/queries)。这是我用来从数据存储区获取所有实体的代码。
def do_the_query_projection(self, kind_name):
query = self.client.query(kind=kind_name)
query.projection = ['attr_1', 'attr_2', 'attr_3']
#create a list to store
f, m, r = [], [], []
for task in query.fetch():
f.append(task['attr_1'])
m.append(task['attr_2'])
r.append(task['attr_3'])
return f, m, r
这是我现在面临的错误
> google.api_core.exceptions.FailedPrecondition: 400 no matching index
> found. recommended index is:
> - kind: <kind_name> properties:
> - name: attr_1
> - name: attr_2
> - name: attr_3
是否有其他方法可以从云数据存储中检索所有数据实体?我们是否需要创建复合索引来检索数据?我是 GCP 的新手。
检索数据存储区中的所有实体
def retrieve_all_entities(self):
query = self.client.query(kind=self.kind_name)
all_keys = query.fetch() #fetches all the entities from the datastore
kinds, r, m, f = [] , [], [], []
for keys in all_keys:
kinds.append(keys.key.id_or_name)
r.append(keys['attr_1'])
m.append(keys['attr_2'])
f.append(keys['attr_3'])
return kinds, r, m, f
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)