Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda