javascriptfirebasefirebase-realtime-database

Firebase .get() vs .once() - What is the difference?


Documentation here but I don't understand: What is the difference between .get() and .once()?

My understanding is that .get() reads from the server, and then from the local storage, and .once() reads only from the local storage. I have used.once() to retrieve values without setting up a listener like .on() and it seems to be retrieving values from the server (realtime database) that I haven't retrieved before so I'm not sure what it means when it says it only searches the local storage... It seems like it is in fact getting values from the server.

Please clarify when to use one vs the other.

I have not used .get() at all.


Solution

  • There is no technical difference per Frank's answer below, but in practice, I receive a ton of "Client is offline" Errors for seemingly no reason when using .get() in Firebase Functions.

    I recommend using .once()

    See issue here for reference: https://groups.google.com/g/firebase-talk/c/VpQms_TnBOw?pli=1