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 ?
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(),
}));
}