Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!