简体   繁体   中英

how to query firestore v9 data in react js

How to perform a query with conditional where() clause using firebase and cloud-firestore v9?

  useEffect(
    () =>
      onSnapshot(
        collection(db, "Article"),
        where("category", "array-contains", "Apple"),
        (snapshot) =>
          setArticles(
            snapshot.docs.map((doc) => ({
              ...doc.data(),
              id: doc.id,
            }))
          )
      ),
    []
  );

You're missing a query call:

onSnapshot(
  query(
    collection(db, "Article"),
    where("category", "array-contains", "Apple"),
  )
  (snapshot) =>
  ...

Also see the Firebase documentation on queries , which has examples for both the v9 SDK and older/other SDKs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM