Reputation: 4987
this.unsubscribe= this.firestore.collection('mycollection').ref.where("somecase","==","myvalue")
.onSnapshot((data=>{}));
I need to make my website live data but when i using above code firestore loading all data for each and every update/insert and it is very costly .
I only need to load newly added data or updated data not all data each and every time.
How to do it in angular6?
This code is in admin website and this is view order page collection is orders And from user app users will make order and the orders will inserts in collection order And what we need is when user make an order we need to view order without refreshing admin page. But now it showing new orders without refreshing but the problem is it is loading all documents inside onSnapshot method when users make an order .we only need to fetching new orders only
Upvotes: 1
Views: 652
Reputation: 25134
So you have the following query:
this.firestore.collection('mycollection').ref.where("somecase","==","myvalue")
When you add a snapshot listener with onSnapshot
you are asking for the results of the query and all future updates. Each time your listener is called we will give you a full QuerySnapshot
. So the first snapshot you get does actually load all of the matching documents from the backend. However if later a single document changes, we will still give you a complete QuerySnapshot which combines the previous results with the newly changed document. In this case you are only charged for a single "read" operation, not the entire set again.
For more information about billing for "listen" operations see this page: https://firebase.google.com/docs/firestore/pricing#operations
Upvotes: 1