All of the docs that have code examples related to firebase.database are for version 8 and below. I’ve intuited a lot from exploring the exported modules themselves, but one thing I can’t figure out how to update is code like ref.once('value').
Other code is now like:
ref.update(data); // old
update(ref, data); // new
But there is no once to do once to use like once(ref, data). Additionally the created refs seem to lack any property to use.
How is this meant to be updated for Firebase 9.x? The Firebase 9 docs don’t seem to offer any example.
>Solution :
firebaser here
The once('value' method has been replace by a get() function, so:
const snapshot = await get(ref);
Also see the Firebase documentation on reading data once.
To unsubscribe from a realtime listener (so not get()) you now can use the return value from the function you called to subscribe.
So if you subscribe with:
const unsubscribe = onValue(ref, (snapshot) => { ... });
You can then later unsubscribe with:
unsubscribe();
This is what the Firestore SDKs already did, and feedback indicated that devs preferred that over off.
