【问题标题】:Is it possible to querty on nested map on firestore where the key is a domain?是否可以查询键为域的 firestore 中的嵌套地图?
【发布时间】:2022-12-14 10:21:41
【问题描述】:

我有一个机构在 firestore 中的集合以及其他数据,我还存储了该机构拥有的域。可能有多个这样的域。

前任 -

domains: {
    sub.domain.com: {
      active: true,
      date_added: timestamp
    },
    anotherSub.domain.com: {
      active: false,
      date_added: timestamp
    }
  },
  name: "Agency Name"

有了这些数据,我想开发一个功能来搜索机构名称基于域(仅当处于活动状态时)。

前任 -

搜索子域名.com应该给我“机构名称”

我正在使用 where 条件来搜索它,但我无法检索任何文档,我想那是因为 firestore 在执行搜索时会将域的点 (.) 转换为嵌套对象。

有什么办法可以做到这一点?

【问题讨论】:

    标签: node.js typescript firebase google-cloud-firestore gcloud


    【解决方案1】:

    您可以使用 FieldPath object 来包装字段名称,并防止 Firestore 将其中的点解析为嵌套字段。

    例如。 (未测试代码):

    where(FieldPath('sub.domain.com', 'active'), '==', true)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      • 2019-07-18
      • 2021-05-04
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2018-10-16
      相关资源
      最近更新 更多