【问题标题】:Why do these queries work independently but not together?为什么这些查询独立工作而不是一起工作?
【发布时间】:2019-04-01 19:29:35
【问题描述】:

我有 2 个查询要用于我的 firestore 集合。

这两个例子有效:

database
  .collection('servicebonnen')
  .where('medewerker', '==', 'CEES')

和:

database
  .collection('servicebonnen')
  .where('date', '>', this.today)
  .where('date', '<', this.tomorrow)

为什么不能像这样组合这些?:

database
  .collection('servicebonnen')
  .where('medewerker', '==', 'CEES')
  .where('date', '>', this.today)
  .where('date', '<', this.tomorrow)

【问题讨论】:

  • 如果您没有收到错误,那么您将不会得到任何结果。这是因为没有数据符合这些条件
  • 第三个查询将所有三个条件与 AND 结合(即 ALL 必须匹配)。所以可能没有数据符合所有标准
  • 你创建了复合索引吗?
  • 您遇到错误了吗?
  • @hkchakladar 看起来这是问题的原因。想把它作为答案发布吗?

标签: javascript firebase vue.js google-cloud-firestore


【解决方案1】:

firestore doc here中提到的:

您还可以链接多个 where() 方法来创建更具体的查询(逻辑与)。但是,要将相等运算符 (==) 与范围或包含数组的子句(、>= 或 array_contains)组合,请确保创建复合索引。

所以你需要在你的情况下创建composite index

【讨论】:

    【解决方案2】:

    正如@hkchakladar 提到的,我需要添加一个复合索引来为非默认查询生成结果。

    【讨论】:

      猜你喜欢
      • 2019-07-13
      • 2020-01-20
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多