I'm planning to query large set of data from Firestore database using NodeJS api. Is there any benefit on using stream api (https://cloud.google.com/nodejs/docs/reference/firestore/0.13.x/Query?#stream) instead of reqular query get (https://cloud.google.com/nodejs/docs/reference/firestore/0.13.x/Query?#get)?
My impression is that streaming is more efficient in terms of memory consumption.
My environment for querying is Firebase functions.
Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database. Realtime Database is Firebase's original database.
One simple option is to add limits to your queries. If you suspect that your user only needs the first handful of results from your employee list, add a limit(25) to the end of your query to download just the first batch of data, and then only download further records if your user requests them.
A Firebase reference represents a particular location in your Database and can be used for reading or writing data to that Database location. The Query class (and its subclass, DatabaseReference ) are used for reading data. Listeners are attached, and they will be triggered when the corresponding data changes.
You can listen to a document with the onSnapshot() method. An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot.
Yes, using stream
over get
will reduce the memory consumption of your Cloud Function! I have experienced it first-hand: my function's memory went from 1GB to 200MB when I replaced get with stream.
To give more details: with the Node.js Admin SDK, in order to access your data:
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