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

106
Vistas
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
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