gcp-从数据存储区获取所有实体 [英] gcp - get all entities from the datastore
本文介绍了gcp-从数据存储区获取所有实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从数据存储中获取所有数据实体.当我遇到Google文档时,发现与查询投影类似(链接到文档).这是我用来从数据存储区获取所有实体的代码.
I am trying to get all data entities from the datastore. When I came across google docs I found something similar to Query Projection (Link to the Docs). This is the code I used to get all entities from the datastore.
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
是否还有其他方法可从Cloud Datastore检索所有数据实体?我们是否需要创建复合索引来检索数据?我是GCP的新手.
Is there any other method to retrieve all data entities from the Cloud Datastore? Do we need to create the composite Indexes to retrieve the data? I am new to the GCP.
推荐答案
要检索数据存储区中的所有实体
To retrieve all entities in the datastore
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
这篇关于gcp-从数据存储区获取所有实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文