lurning too koad
lurning too koad

Reputation: 2974

How to create a composite index that includes a map?

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.

Upvotes: 1

Views: 612

Answers (1)

lurning too koad
lurning too koad

Reputation: 2974

Update: this is, unfortunately, not possible. The composite index requires that each key in the map be given its own index. And with the limit that Firestore puts on how many composite indices are allowed in a database (not collection), this definitely is an antipattern for large maps.

Upvotes: 1

Related Questions