0

I'm trying to perform a filter and sort query, but I want to put it inside a function. How can I do that ?

I'm trying to do this

const handleFilter = () => {
  const q = query(collection(db, "location"), where ("location", "==", "Pasig"));

  const querySnapshot = await getDocs(q);

  querySnapshot.forEach((doc) => {
    (doc.id, " => ", doc.data());
  });
}

But it is not working.

1
  • Please be sure to include how it's not working. Commented Jul 19, 2022 at 4:37

1 Answer 1

1

To use await keyword inside a function it needs to be declared as an async function. Try the following:

const handleFilter = async () => {
const q = query(
  collection(db, "location"),
  where("location", "==", "Pasig")
);

const querySnapshot = await getDocs(q);

querySnapshot.forEach((doc) => {
  doc.id, "=>", doc.data();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.