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

102
Vistas
Firestore in query problems

I have an array field in Firestore that looks like that ['west_coast', 'east_coast'] I want to get results if west_coast and east_coast are found in the same array from dynamic data

It works when I do it as in the example on the Firestore site.

const exactlyOneCoast = await citiesRef.where('region', 'in',[['west_coast', 'east_coast']]).get();

but since the data comes dynamically, if the place of the data in the array is different, it does not give any results.

const exactlyOneCoast = await citiesRef.where('region', 'in',[['east_coast', 'west_coast']]).get();

I want it to find it even if they change places. Is there a way to do this?

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

0

If you have an array field called "region" that holds two values "east_coast" and "west_coast", then there is no way you can use the following query:

const exactlyOneCoast = await citiesRef.where('region', 'in',[['west_coast', 'east_coast']]).get();

Nor:

const exactlyOneCoast = await citiesRef.where('region', 'in',[['east_coast', 'west_coast']]).get();

Why? Because the in operator works only against a field of type String and not against a field of type array. So if you have a field of type String, the in query returns documents where the given field matches any of the comparison values.

If you need to check if a particular value exists in an array, then you should use the array_contains operator. Since you cannot chain multiple such calls, then you should perform multiple separate database calls.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The query you are doing is looking for an exact array match [docs]

You can use an array value as a comparison value for in, but unlike array-contains-any, the clause matches for an exact match of array length, order, and values.

If you drop one set of brackets, it will return if region is either west_coast or east_coast

citiesRef.where('region', 'in',['east_coast', 'west_coast'])

The in, array_contains, and array_contains_any operators are logical OR searches, so if you want to return documents where an array (in your document) contains both elements, then you need to do a compound query. However, you cannot do multiple array_contains queries. You would instead need to do multiple queries separately and then build your own logic around them.


Edit: Fixed the chaining array_contains issue that I forgot about.

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