Home > Enterprise >  Create firestore index from firebase admin SDK with emulator
Create firestore index from firebase admin SDK with emulator

Time:09-21

The recommended way to create indexes for firestore is to use the query you're trying to do in your source code and then clicking on the generated link.

However, when using the emulator, and running the desired query, nothing happens. This is the query I am trying to do:

await firestore.collectionGroup('collectionName').where('specificField', 'array-contains-any', ['']).get();

Since I'm using the emulator, it returns the correct response, but doesn't give me a link to create the actual index in firestore. Do I have to run the code on production in order to get that link?

If anyone also knows how this index should look like in the firestore.indexes.json file I would appreciate that too!

CodePudding user response:

See: https://github.com/firebase/firebase-tools/issues/2027

tl;dr - as of Sept '22, the local emulator 'just works' and does not require (or warn/prompt for) composite indexes.

I cannot find any info on how to tease out the required indexes, so it appears devs using the emulator need to 'eyeball' the problem or otherwise somehow catch it themselves.

(Really sketchy aspect of Firestore emulator dev imo - yeesh.)

  • Related