Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
How to use ref.once with Firebase 9?

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.

enter image description here

How is this meant to be updated for Firebase 9.x? The Firebase 9 docs don't seem to offer any example.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Heads up (~24 Jun 2022; firebase v9): While get() is the recommended way to read data once (see Frank's post), there are currently some unresolved issues with get() where a client's execution of multiple queries with different filters on the same ref path somehow causes interference between the queries resulting in the unexpected triggering of events (see links below). I also experienced this and it's quite hard to debug. It is probably caused by get()'s caching mechanism as hinted at by the issues below:

  • [realtime database] concurrent queries on the same path don't work #515
  • Queries to the same database path get mixed up and return incorrect results depending on order of execution #6038

Workaround: Instead of retrieving results via get(), you can also use onValue() (see value observer) and then disconnect it immediately after the item has been returned:

const val = await new Promise((resolve, reject) => {
  onValue(query, (snap) => resolve(snap.val()), { onlyOnce: true });
});

Disclaimer: Note that onValue() in combination with onlyOnce: true will return values from firebase's local disk cache immediately (if present), instead of checking for an updated value on the server first (as it is the case with get()).

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda