HONG HONG Choy
HONG HONG Choy

Reputation: 15

firebase firestore nested request

I have a nested firebase structure as shown:

-users (collection)
      - user 1  (document)
            -Order (collection)
                 -Order1 (document)
                 -Order2 (document)
            -Personal Information (collection)

      - user 2  (document)
            -Order (collection)
                 -Order1 (document)
                 -Order2 (document)
            -Personal Information (collection)

...etc

How would I be able to list the name of all Users like [user1, user2, ...]

  const getOrders = async () => {
    await firestore()
      .collection("users")
      .get()
      .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
          console.log(doc.id);
        });
      });
  };

I have tried this set of code but does not work.

Upvotes: 0

Views: 281

Answers (1)

mpmcintyre
mpmcintyre

Reputation: 717

I am more familiar with firebsase's RTDB but I managed to scrape this from their docs:

import { collection, query, getDocs } from "firebase/firestore";

const q = query(collection(db, "users")

const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
  console.log(doc.id, " => ", doc.data());
});

Hope it works!

Read more here

Upvotes: 1

Related Questions