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

181
Vistas
Updating multiple docs in firebase

let's say that i wanna update a serie of documents, i'm doing it using forEach like this.

students.forEach(async (name) => {
      const docRef = doc(db, "students", name);
      await updateDoc(docRef, {
        school: "Some School",
      });
    });

And it's working fine, but i was wondering if that's bad for sending too many requests or something. Is there another better/smarter way to do it?

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

I usually recommend against using await in a scenario where you are using updateDoc on a sequence of documents, as it's actually faster to let the updates run in parallel. For more on this, see What is the fastest way to write a lot of documents to Firestore?

But the await here is harmless, since using await in a forEach has no impact on the other operations in that same forEach. For more on this, see: Using async/await with a forEach loop If you were to use a for of loop though, be sure to remove the await for improved throughput.

about 4 years ago · Santiago Gelvez Denunciar

0

There's nothing particularly "bad" about this given what you've shared, unless you are also observing some behavior that you don't like.

If your intent is to update all of the documents atomically (up to a limit of 500 in a batch), so that any failures or interruptions won't leave the set of documents in an inconsistent state, you are better off using a batch write instead. But that won't necessarily give you any better performance or other improved runtime behavior.

about 4 years ago · Santiago Gelvez 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