【发布时间】:2021-08-11 15:10:41
【问题描述】:
是否可以在 Google Firestore 中查询一个集合,然后根据子集合值对其进行过滤?
我的意思是我得到了这个数据结构:
/
| repo/
| - title: title,
| - journal: Nyt,
| | category/
| | - name: News
我尝试用这种方式查询(例如检索 Nyt 分类新闻的所有文章):
db.collection('repo')
.where('journal', '==', 'Nyt')
.collection('category')
.where('name', '==', 'News')
但是'Query' object has no attribute 'collection'.
我也尝试以这种方式构造数据:
/
| repo/
| - title: title,
| - journal: Nyt,
| - category: [
| | - news: News,
| | - tech: Tech,
然后通过 db.col('repo')....where('category.news', '==', 'News') 查询,但不幸的是我还需要 order_by 其他字段,因此 Firestore 要求为 db 中的每个类别建立索引...
【问题讨论】:
标签: python google-cloud-firestore