I'm using google's firestore and I want to get a live update on the entire collection.
I saw this in the documents: https://cloud.google.com/nodejs/docs/reference/firestore/0.11.x/CollectionReference#onSnapshot
but as far as I understood I have to get a document or to query a range of documents.
how can I listen to changes in the entire collection?
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");
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With