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

104
Views
How to batch addDoc in firestore?

I followed the tutorial here on how to batch write items to Firestore. However, this does not seem to work as I get a type error

Argument of type 'CollectionReference<DocumentData>' is not assignable to parameter of type 'DocumentReference<DocumentData>'.
  Types of property 'type' are incompatible.
    Type '"collection"' is not assignable to type '"document"'
const batchLog = async (
  data: LogData[] & CommonLogData[],
  sessionId: string | null,
) => {
  if (!sessionId) {
    console.error('attempting to log item without a session id', data);
  }
  // Get a new write batch
  const batch = writeBatch(db);

  // for each data, set the batch
  data.forEach(datum => {
    const docRef = collection(
      db,
      rootCollection,
      sessionId || 'error',
      datum.collection_name,
    );
    batch.set(docRef, doc);
  });

  await batch.commit();
};

Quite simply, I want to be able to run an addDoc but have it batched. It seems as if this only works for the documents but not collections. I am very new to this, so any help would be appreciated. Currently, I believe this code fails silently (I don't see my data in the firestore update)

about 4 years ago · Juan Pablo Isaza
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!