Augustine C Augustine C - 6 months ago 38
Node.js Question

Cloud Functions for Firebase: Reading the Entire Database into Memory

I would like to read the entire Firebase database into a variable from inside a backend Cloud Function, as follows:

exports.transformUserData = functions.https.onRequest((request, response) => {

admin.database().ref('/').on('value', function (snapshot) {

var dbData = snapshot.val();
...

});
...
});



  1. Is this safe? (From a memory or dollar cost perspective, speed is not an issue in this case).

  2. I expect the function will crash once my database grows due to an out-of-memory error. If this is the case, at what memory limit can we expect it to crash? (For example, 10MB).



Thank you in advance for any advice!

Answer Source

It is technically totally possible to read all data from your Firebase Database into memory.

As long as the hosting process has enough memory available this will work. If there is not enough memory, the script will crash.

It is impossible to say at what amount of memory this will crash, since this depends on the JSON data size, the data format (many small nodes will use more memory than one big node), and other factors.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download