Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!