question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Firestore indexes to local emulator

See original GitHub issue

[REQUIRED] Environment info

firebase-tools: 7.15.0

Platform: Ubuntu 18.04.4

[REQUIRED] Test case

I’m trying to test our Firestore indexes, but they seem to always be working (regardless of the indexing settings included in firestore.indexes.json). Below is the test case in question:

const FILTERS = {
    'grade': ['==', TUTOR.grade],
    'gender': ['==', TUTOR.gender],
    'location': ['==', TUTOR.location],
    'type': ['==', TUTOR.type],
    'payments.type': ['==', TUTOR.payments.type],
    'config.showProfile': ['==', true],
};
const SORTERS = [
    'avgRating',
    'numRatings',
];

describe('Tutorbook\'s Database Indexing', () => {
    const db = authedApp({
        uid: PUPIL.uid,
        email: PUPIL.email,
        access: PUPIL.access,
    });
    const filterCombos = combinations(Object.keys(FILTERS));
    return Promise.all(filterCombos.map(filters => it('lets users filter ' +
        'profiles by ' + filters.join(', '), () => {
            var query = db.collection('users')
                .where('access', 'array-contains-any', PUPIL.access);
            filters.map(filter => query =
                query.where(filter, FILTERS[filter][0], FILTERS[filter][1]));
            return Promise.all(SORTERS.map(sorter =>
                firebase.assertSucceeds(query.orderBy(sorter).get())));
        })));
});

[REQUIRED] Steps to reproduce

Just try testing any type of composite or collection group query that would (normally) require an index. It will work on the emulator suite regardless of the existence of the required index (but it won’t work in production without the index).

[REQUIRED] Expected behavior

These tests should fail unless there are Firestore indexes (specified in firestore.indexes.json) that support the composite indexes tested.

[REQUIRED] Actual behavior

All the tests succeed (even though they shouldn’t).

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:88
  • Comments:50 (17 by maintainers)

github_iconTop GitHub Comments

55reactions
dahu33commented, Jan 31, 2022

Any update on this? It’s unbelievable that in 2022 we can still ship broken code to production because of such issue…

26reactions
samtsterncommented, Mar 31, 2021

@IchordeDionysos fully agree! This is really hard to test and we want to improve it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage indexes in Cloud Firestore - Firebase - Google
Go to the Cloud Firestore section of the Firebase console. · Go to the Indexes tab and click Add Index. · Enter the...
Read more >
Create firestore index from firebase admin SDK with emulator
The recommended way to create indexes for firestore is ...
Read more >
Emulate Firestore locally
Run the following command to start the emulator: gcloud emulators firestore start. The emulator prints the host and port number where it is...
Read more >
The Full Guide on how to use the Firebase Emulator ...
Once you added all the data to Firestore if you stop the emulator and start it again, it will start empty, so you'd...
Read more >
Firestore: Can't create missing index by clicking on link (url ...
If you are using firebase functions, you can serve the local emulator and hit your firestore query... it will then return you an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found