Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
How can I prevent having multiple combinations of Firestore Indexes

Basically, I have a query from Firestore, and some of the filter fields may be empty, in that case the specific query will be ignored,Since inequality queries with multiple fields requires indexes, what's the best way to create indexes of such query without going through all possible combinations.

e.g, 'country' and 'budget_high', 'gender' and 'budget_high', 'age' and 'budget_high', 'country, gender' and 'budget_high' and so on.

This is my query.

if (country !== "") query = query.where("country", "==", country);
  if (gender !== "") query = query.where("gender", "==", gender);
  if (age !== "") query = query.where("age", "==", age);
  if (religion !== "") query = query.where("religion", "==", religion);
  if (budget_high !== "") query = query.where("budget_high", "<=", Number(budget_high));
  return query
    .get()
    .then((querySnapshot) => {
      var data = [];
      querySnapshot.forEach((doc) => {
        let user_data = doc.data();
        user_data.created_at = `${user_data.created_at.toDate()}`;
        data.push(user_data);
      });
      return data;
    })
    .catch((error) => {
      console.log("Error getting documents: ", error);
      return [];
    });
};

Here are my Single Field Exemptions for collection (not collection group) enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

First, we need a field that will be present in all queries. You can orderBy one of the fields inorder for it to always be present (budget_high in this case since you are calling inequality query on it).

So create 4 composite indexes.

  1. budget_high and country ASC
  2. budget_high and gender ASC
  3. budget_high and age ASC
  4. budget_high and religion ASC

This will effectively handle your query combinations.

Read the merging index docs

about 4 years ago · Juan Pablo Isaza Denunciar

0

Following up on @Peter O. response, the order of the fields in the indexes is important. Please try the following:

  1. country ASC and budget_high
  2. gender ASC and budget_high
  3. age ASC and budget_high
  4. religion ASC and budget_high

I hope this helps.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda