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

136
Views
How can I make this Firestore query?

I'm a Firestore newbie and I need to make a query. I have this database structure:

{
  "businesses": {
    "1" : {
      "name": "bla",
      "employees": {
        "1" : {
          "name": "Juan",
          "schedules": {
            "1": {
              "scheduleId" : "72",
              "from": "21/08/2020"
            }
          }
        },
        "schedules": {
          "72": {
            //some properties
          }
        }
      }
    }
  }
}

Given a businessId and a scheduleId, I need to fetch all the business' employees having that scheduleId assigned.

I have tried this:

export async function getEmployeesWithSchedule(businessId: string, scheduleId: string): Promise<Employee[]> {
    const docs = (await admin.firestore().collection(`businesses/${businessId}/employees`)
         .where("schedules.scheduleId", "==", scheduleId)
         .get()).docs;
   //extract results
}

But I'm geting no results. How should I make this query?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try the following where clause. You should only get back docs where the schedules map contains a key-value-pair with key scheduleId and a non-null value:

const docs = (await admin.firestore().collection(`businesses/${businessId}/employees`)
         .where(`schedules.${scheduleId}`, "!=", null)
         .get()).docs;
about 4 years ago · Santiago Trujillo 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!