1

I am making my first angular/Firestore app and I am having some trouble understanding how to retrieve data in nested collections. My Firestore dB path I want to read from is here:

/Customer(CollectionName)/cl0Apvalb6c0w9hltQ8AOTF4go23(userUIDby)/Order(subcollectionName)/7WqHl5YUKPszkRELXEI2(auto-id)

So Customer is a collectionName, cl0Apvalb6c0w9hltQ8AOTF4go23(USERUID) is a USER-UID for a user. Authentication, Order another collectionName, and 7WqHl5YUKPszkRELXEI2 is an auto-id for an added order.

In this each user can GET its own data but as Admin I want to get to see all user data.

I want All FIRESTORE data of users to display on angular as I am making an admin panel in angular 12.

export class OrderlistsService {

    itemsCollection!: AngularFirestoreCollection<Item>;

    items!: Observable<Item[]>;

    itemDoc!: AngularFirestoreDocument<Item>;

    constructor(private firestore: AngularFirestore) {}

    getOrdersItems() {
       return this.firestore.collection<Item>('customer').valueChanges();
    }}

1 Answer 1

3

If you want to load the orders from all users, you're looking for a collection group query. In AngularFire that'd be:

this.firestore.collectionGroup<Item>('Order').valueChanges();

This reads the documents from all subcollections named Order, no matter where they exist in your database.

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.