How to create a composite index that includes a map?

时间:2019-01-09 21:40:39

标签: firebase google-cloud-firestore

I have a collection that contains three properties that I want to create a composite index for but keep getting an error that says I need a composite index for this query. This is the collection data model:

active: boolean
date: string
nameComponents: map
    "nameComponent": boolean

The document would look something like this:

active: true
date: "2019-02-18"
nameComponents:
    "pineapple": true
    "pie": true

The query would look something like this:

Firestore.firestore().collection("someCollection").whereField("active", isEqualTo: true).whereField("nameComponents.pineapple", isEqualTo: true).whereField("date", isLessThanOrEqualTo: "2019-12-31").whereField("date", isGreaterThanOrEqualTo: "2019-01-01")

I created the following composite index, without any luck:

active: ascending, date: ascending, nameComponents: ascending

How do I create a composite index for this query? And the links to create the composite index in the debugger always, since always, taken me to a webpage that says unknown error.

1 个答案:

答案 0 :(得分:0)

更新:很遗憾,这是不可能的。复合索引要求给映射中的每个键赋予其自己的索引。而且由于Firestore限制了数据库(而非集合)中允许有多少个复合索引,因此这绝对是大型地图的反模式。