With the new Firestore from Firebase, I discovered that I have poor knowledge with Observables.
My problem is the following:
I get some data with db.collection('room').
If I don't listen to the observable with a subscription, do I fetch the document? (I think so).
For every change in my collection "room", is it considered as a "new document read" by Firestore?
If I have duplicated Observables which return db.collection('room') in my app, will I have X calls to the Firestore database or just one?
Thanks!
Cloud Firestore allows you to listen to the results of a query and get realtime updates when the query results change. When you listen to the results of a query, you are charged for a read each time a document in the result set is added or updated.
If you need a count, just use the collection path and prefix it with counters . As this approach uses a single database and document, it is limited to the Firestore constraint of 1 Update per Second for each counter.
There is no limitation on the number of documents in Firestore collection but it has a limitation of the size of the document. The maximum size of a document is roughly 1 MiB (1,048,576 bytes). Show activity on this post.
Use of the Firebase console will incur reads. If you leave the console open on a collection or document with busy write activity then the Firebase console will automatically read the changes that update the console's display. Most of the time this is the reason for unexpected high reads.
- If I don't listen to the observable with a subscription, do I fetch the document? (I think so).
When you call var ref = db.collection('room')
, ref
is not really an observable it is a reference to the 'room'
collection. Creating this reference does not perform any data reads (from network or disk).
When you call ref.get()
or ref.onSnapshot()
then you are fetching the documents from the server.
- For every change in my collection "room", is it considered as a "new document read" by Firestore?
If you are listening to the whole collection (no where()
or .orderBy()
clauses) and you have an active onSnapshot()
listener then yes, you will be charged for a document read operation each time a new document is added, changed, or deleted in the collection.
- If I have duplicated Observables which return db.collection('room') in my app, will I have X calls to the Firestore database or just one?
If you are listening to the same Cloud Firestore data in two places you will only make one call to the server and be charged for the read operations one time. There's no cost/performance penalty to attaching multiple listeners to one reference.
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