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

243
Vistas
Batch delete documents of a subcollection error: TypeError: n.indexOf is not a function

I am trying to batch delete a document of a subcollection.

There are times when I might need to delete the same product document ID and different history document ID or multiple product document IDs and different history document IDs.

I am passing the product document ID and history document ID, and I already see them in the console. However, I receive this error once I try to batch.delete() this:

This is what the docID and the historyId shows in the console:

enter image description here

import {
  doc,
  getDoc,
  updateDoc,
  deleteField,
  collection,
  getDocs,
  addDoc,
  increment,
} from "firebase/firestore";
import { db } from "../../Firebase/utilities";

async function deleteDocumentSubcollection(docID, historyId) {
try {
  const batch = writeBatch(db);

//I think this is where the error appears
  historyId.forEach((id) => {
    batch.delete(doc(db, "products", docID, "history", historyId));
  });

  await batch.commit();
  alert("deleted");
 

  console.log("deleted");
} catch (err) {
  console.log(err);
}
}

package.json

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As stated in the documentation, the docId and historyId should corresponds to the specific Ids of documents. You can try to delete specific documents using their corresponding IDs, and just a note, IDs should not be array:

historyId.forEach((id) => {
    batch.delete(doc(db, "products", "documentId", "history", id));
});
about 4 years ago · Juan Pablo Isaza 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