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

177
Vistas
Firestore: Get multiple documents via complex fieldPath (where function)

I safed different products in my Firestore and they are available for purchase on different days of the week. So I safed the availability on different days as an Array of 7 boolean values in my Firestore.

weekdays = [true, true, true, false, false, true, false];

Now if I wanna get all products that are available on Friday I would have to do something like this:

// assume date.getDay() is 5

const q = query(
  collection(db, "bakerys", `${bakery.id}`, "products"), 
  where(`weekdays[${date.getDay()}]`, "==", "true")
);
const querySnapshot = await getDocs(q);

This doesn't seem to work. Do I really have to store every weekday in its own value separately in order to make this work or is there a way to get this work differently.

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

0

You can just store the days directly instead of a boolean value like this:

weekdays = ['Monday', 'Friday'];

Then execute this query:

const q = query(
  collection(db, "bakerys", `${bakery.id}`, "products"), 
  where(`weekdays`, "array-contains", "Monday")
);

This query will fetch all documents where the weekdays array contains Monday. If you want to store boolean values with day index then you would have to store a map like this:

weekdays = {
  1: true,
  5: false
}

Here you can use the following query:

const q = query(
  collection(db, "bakerys", `${bakery.id}`, "products"), 
  where(`weekdays.${date.getDay()}`, "==", true)
);

Additionally do note that your original array contains boolean values but your query had "true" (string). Make sure the types in db and query match.

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