繁体   English   中英

在 Firestore 中查询集合组

[英]querying collection group in firestore

我刚刚开始使用 firestore,我有一个关于如何查询数据的问题。

我有这样的记录结构

{
"idName": "aquarobur",
"displayName": "Aqua Robur Technologies",
"categories": {
 "orgtype": [ "private"],
  "sdg": [ "11","17"],
  "segment": [ "building-and-construction", "consulting"]
 }
}

我想过滤/查询“类别”值。 例如:获取所有具有“segment”和“building-and-construction”的记录

const snapshot = catalog_entryRef.where('categories.segment', '==', 'building-and-construction').get()

我试过这个。 但它不返回任何记录。 在我看来,我只能查询记录第一级的字段。 例如,我可以像这样使用“idName”进行查询

const snapshot = catalog_entryRef.where('idName', '==', ‘aquarobur’).get()

在查询中使用==进行相等检查。 因此,它只返回字段具有您指定的完整、准确值的文档。

您需要一个array-contains操作来满足您的需求:

catalog_entryRef.where('categories.segment', 'array-contains', 'building-and-construction').get()

有关更多信息,请参阅有关数组成员资格的 Firebase 文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM