Firestore onSnapshot -> Does it work for subcollections?

Viewed 2769

Is the method onSnapshot of firestore triggered by any changes in subcollections?

What is the difference between db.firestore.collection('x'). onSnapshot

And db.firestore.collection('x').doc('y').collection('z'). onSnapshot

Are they equal????

1 Answers

A change to a subcollection organized under a document do not count as changes to the document itself. They will not trigger a snapshot event on that document.

Listening to a subcollection is not any different than listening to a top-level collection. In both cases, the listener will only be triggered by changes to documents within that collection or subcollection.

Related