Python 3.x firestore使用单个读取操作从集合中获取所有文档
目前,我使用以下查询查询firestore数据库:Python 3.x firestore使用单个读取操作从集合中获取所有文档,python-3.x,google-cloud-platform,google-cloud-firestore,Python 3.x,Google Cloud Platform,Google Cloud Firestore,目前,我使用以下查询查询firestore数据库: def get_db_from_cloud(self): """ gets all the info in the db back to the flask app as a dictonary ready to be cached """ docs = self.db.collection(self.collection_name).strea
def get_db_from_cloud(self):
"""
gets all the info in the db back to the flask app
as a dictonary ready to be cached
"""
docs = self.db.collection(self.collection_name).stream()
docs_dict = {}
for doc in docs:
self.logger.debug(f'{doc.id} => {doc.to_dict()}')
docs_dict[doc.id] = doc.to_dict()
return docs_dict
这将遍历self.collection\u name
中的集合,并返回正确的信息。
当我分析这一点时,我可以看到firestore使用情况仪表板中的使用情况随着我拥有的文档数量的增加而增加。当我遍历整个集合时,这是有意义的。
我搜索了,但找不到是否可以使用单个读取操作检索整个集合
由于这个特定的集合仅由管理员更改(而且很少更改),因此在启动时将整个数据库加载到缓存对我来说很方便,我希望将其优化为尽可能低的成本
那么,有可能吗?如果没有,是否有其他建议如何限制对firestore的读取调用量?对于firestore,无法使用单个读取操作查询多个文档。查询的读取次数始终等于返回的文档数(对于不返回文档的查询,最小读取次数为1次)
如果你想降低存储和获取这些数据的成本,考虑使用不同的产品。
谢谢,我将把我的数据库迁移到另一个解决方案,研究现在的替代方案。