How can I receive all document objects from a collection in cloud-firestore?

When I try to receive a document from a subcollection I get an object with only the values from the document.

The response looks like this:

{
 id: mealDocumentId,
 name: 'Burger',
 imageUrl: 'imgUrl1',
 price: 3, quantity: 1
} 

Is there a way to receive the object from the entire document?

I was expecting the objects from the documents similar to this:

 {
  mealDocumentId1: {
    name: 'Burger1',
    imageUrl: 'imgUrl1',
    price: 1,
    quantity: 1,
  },
  mealDocumentId2: {
    name: 'Burger2',
    imageUrl: 'imgUrl2',
    price: 2,
    quantity: 2,
  },
 }

The Code I’m running:

 constructor(private db: AngularFirestore) { }

  getAllMealDocuments() {
    // this is the path to the subselection meals
    const docRef = this.db.collection('tables').doc('documentId').collection('meals');
    
    // try to get a document object and pass it.
    return  docRef.snapshotChanges().pipe(map(document => {
      document.map(doc => {
        return new Meal({
          id: doc.payload.doc.id,
          ...(doc.payload.doc.data() as {})
        });
      });
    }));
  }

Is there another way to receive all the documents? Preferably like the expected formate? Thanks!

Answer

It sounds like you’re looking for the documentChanges stream, which (unlike valueChanges) includes the ID of each document in its output.

I’d recommend checking out the AngularFire documentation on streaming collection data for the types of streams, and the differences between them.