Search code examples
firebasegoogle-cloud-firestore

Does Firestore Query with range and inequality filters on multiple fields still require Composite Index?


I saw the news that Firestore is now allowing inequality filters on multiple fields but my question if you still need to create a composite index at a collection level in order to do this? Previously it was the case that you could do inequality filters on multiple fields by creating a composite index at a collection level so has this changed?

When trying using the modular API I am still getting the error message that I need to create a composite index at the collection level.

In my scenario the collection name is unique to each user so I cannot create composite indexes.

Update: importing using url 'https://www.gstatic.com/firebasejs/10.11.0/firebase-firestore.js'

import { collection, query, where, getDocs, getFirestore } from 'https://www.gstatic.com/firebasejs/10.11.0/firebase-firestore.js'


Solution

  • As far as I know, the new feature doesn't change anything about what indexes are required - it "just" uses then differently.

    From the description it sounds like you've already discovered the answer yourself: yes, you need to add an index for each specific field combination you want to query.