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

106
Vistas
Filter firestore request by separate steps

I am making a filter so that a user can search for exactly a few parameters, without having to put them all in the form. For example you could search for games of type X but of all genres (Leave the form empty and it is an empty array).

I had tried doing the whole query at the same time but since there are empty arrays an exception is thrown. Consequently, I have thought of going step by step checking the filter parameters and discarding the empty ones, but I don't know how to save each step in the reference.

Technologies:

  1. Ionic
  2. Angular
  3. Firebase - Firestore

Service Code:

getFilteredResultsGames(filter: Filter) {
return this.firestore.collection<Game[]>(environment.db_tables.games,
  (ref) => {

    if (filter.types.length > 0){
      ref.where('id_type', 'in', filter.types)
    }
    if (filter.genders.length > 0) {
      ref.where('ids_genders', 'array-contains-any', filter.genders)
    }

    return ref
  }).valueChanges({ idField: 'id' });

}

Model Code:

export interface Filter {
  genders: string[];
  types: string[];
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Firestore queries objects are immutable. Calling where on a ref or query, doesn't modify the existing object, but rather returns a new query with the additional condition.

So to return the new query, you'd do something like:

getFilteredResultsGames(filter: Filter) {
return this.firestore.collection<Game[]>(environment.db_tables.games,
  (ref) => {
    if (filter.types.length > 0){
      ref = ref.where('id_type', 'in', filter.types)
    }
    if (filter.genders.length > 0) {
      ref = ref.where('ids_genders', 'array-contains-any', filter.genders)
    }

    return ref
  }).valueChanges({ idField: 'id' });
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