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

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

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 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!