【问题标题】:How to query the array from the firestore using javascript?如何使用javascript从firestore查询数组?
【发布时间】:2021-12-10 07:59:51
【问题描述】:

所以,我有一个如下图所示的 Firestore。如何查询我仅突出显示为 javascript 格式的数组?

Getting started with firestore 的作用是使用 [array-contains](https://firebase.google.com/docs/firestore/query-data/queries#:~:text=const%20q%20%3D %20query(citiesRef%2C%20where(%22regions,array_contains_filter.js) 作为他们的例子:

const q = query(citiesRef, where("regions", "array-contains", "west_coast"));

但我看到的是它只显示'west_coast'这个词,我想要的是它会在名为'amount'和'title'的字段中显示任何信息,如上图所示

【问题讨论】:

  • 显示的数据取决于您从 Firestore 获取数据后要打印的数据。你能分享你查询和打印数据的完整代码吗?获取数据后,您似乎做错了什么。
  • 看看这个问题的答案stackoverflow.com/questions/54600915/…

标签: javascript firebase google-cloud-firestore


【解决方案1】:

恐怕你不能。您需要检索整个products 数组并在本地进行过滤。

这决定了您的数据在 Firestore 中的结构。如果这是您需要的查询,那么您的数据可能具有不同的结构。

例如:

  • products 可以是 ordered 的子集合
  • 或者,ordered 文档可能会将您需要查询的数据存储在一个单独的简化数组中(如 titles: [...], amounts: [...],但无论如何这对排序或数字范围没有帮助)。

看看: https://firebase.google.com/docs/firestore/manage-data/structure-data 对于这样的示例和用例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-02
    • 2020-01-25
    • 1970-01-01
    • 2022-01-03
    • 2020-04-07
    • 2020-07-22
    • 2021-04-15
    • 2019-10-27
    相关资源
    最近更新 更多