Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

303
Visualizações
React JS: How to pass an array from firebase in query parameter?

I'm using multiselection in one of my parameters and I would like to know how to query those parameters like for example if

I want to query parameters that has 1 (doesn't matter if there are other values)

Value one has : 1, 2, 3 Value two has: 5, 1, 6 Value three has: 5, 6, 9

It should only bring Value one and two

I know you can do something like (for non array values):

const librosRef = db.collection('libros');
const queryRef = librosRef.where('grado', '==', '4° Grado');

and it would bring all the documents in that collection that has 4° Grado but if I try to do that while using a multiselection it doesn't bring anything.

This is what I'm trying (doesn't work for array which is what I'm trying to figure out):

const productosRef = db.collection('productosAIB');
    const queryRef = productosRef.where('grado', '==', '4° Grado');

    useEffect(() => {
        queryRef.orderBy("precio")
        .get()
        .then((snapshot) => {
              const tempData = [];
            snapshot.forEach((doc) => {

              const data = doc.data();
              tempData.push(data);
            });
            setProductos(tempData);
          });
      }, []);

Example of how it gets stored in the Firebase:

enter image description here

And this is how it looks in the table (without the query because if I add the query it doesn't show anything )

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It sounds like you're trying to query for documents based on the existence of a value in an array. These are called array membership queries in Firestore.

For this, you would use array-contains to match a single field in an array, and array-contains-any to match any value from an array.

To query based on single value in array

const queryRef = productosRef.where('grado', 'array-contains', '4° Grado');

multiple values passed in as an array

const queryRef = productosRef.where('grado', 'array-contains-any', ['4° Grado', 'next array element']);

NOTE: array-contains-any can support up to 10 comparison values.

For more information on array membership queries you can see the documentation here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda