Firestore 复合查询不返回数据

Firestore compound query not returning data

我尝试使用 whereGreaterThan 和 whereArrayContains 复合查询从 Firestore 获取数据。出于某种原因,这种组合似乎不起作用。如果我省略了它们起作用的两个语句之一,并且 return 几乎相同的数据。

    someCollection
        ?.whereGreaterThan("date", Date().startOfPreviousMonth)
        ?.whereArrayContains("ids", id)
        ?.get()
        ?.addOnSuccessListener { .... }
        ?.addOnFailureListener { .... }

在文档中只说明复合查询只有这些限制:

Limitations

Note the following limitations for != queries:

  • Only documents where the given field exists can match the query.
  • You can't combine not-in and != in a compound query.
  • In a compound query, range (<, <=, >, >=) and not equals (!=, not-in) comparisons must all filter on the same field.

对我来说,这些都不符合我的问题。有什么建议吗?

如果不创建 .

,则无法在同一个查询中使用 whereGreaterThan()whereArrayContains() 方法调用

创建相应的索引,可以在 Firebase 控制台中手动创建,也可以通过单击 Android Studio logcat 中的 link 自动创建。

在 Android 中,您可以附加一个失败侦听器并从错误消息中获取 URL。