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

96
Views
firebase query method where clause with AND

I want to do a WHERE foo = bar AND something = also_something in firebase

export const getAllRoomsWhichHaveUnreadMessages = (currentUserId) => {

    return query(
        roomsRef,
        where(USERS_PATH, 'array-contains', currentUserId), 
        where('unreadCount', '>', 0)
    )
}

How do I chain WHEREs and also how do I retrieve them? My above code works but it only outputs a query, how do I run the query ?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You will need to use the getDocs method to get a snapshot of the query.

You can then map the docs of that snapshot.

import { query, where, getDocs } from "firebase/firestore";
    export const getAllRoomsWhichHaveUnreadMessages = async (currentUserId) => {

    const q = query(
        roomsRef,
        where(USERS_PATH, "array-contains", currentUserId), 
        where('unreadCount', '>', 0)
    )

    const querySnap = await getDocs(q);
    return querySnap.docs.map((doc) => ({
          id: doc.id,
          ...doc.data(),
        }));
    }

about 4 years ago · Santiago Gelvez 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!