firestore - listen to update on the entire collection
From my current experience, .onSnapshot
without query (.where
) helps you listen to the whole collection. E.g
db.collection('cities')..onSnapshot(function(querySnapshot) {
var cities = [];
querySnapshot.forEach(function(doc) {
cities.push(doc.data().name);
});
console.log("Current cities in CA: ", cities.join(", "));
});
Source: https://firebase.google.com/docs/firestore/query-data/listen
You can read more there too.
If you refer back to the Listen to multiple documents in a collection documentation, simply omit the where filter and you should get the whole collection.
The first line would look like this: var query = db.collection("cities");