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

200
Vistas
How delete documents from a Firestore collection with a 'where' clause in Web v9

I'm struggling to complete the following code:

const myCollection = collection(db, 'myCollection');
const mycollectionQuery = query(myCollection, where("field1", "==", "xyz"));
myCollectionSnapshot.forEach((doc) => {
     deleteDoc(?);
});

Advice on what to supply inside the deleteDoc call would be much appreciated. I was pretty confident it would be doc.id, but this returns a "Cannot use 'in' operator to search for '_delegate' in undefined" error message

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

0

In V9, the deleteDoc() method takes a DocumentReference, as documented here.

As you can see from the documentation of your forEach(), the doc variable will be a QueryDocumentSnapshot, that is a specialization of DocumentSnapshot. It means that, if you want to retrieve the DocumentReference for your doc, you just need to reference to it via doc.ref.

In other words, to delete the document you'll need to do this:

myCollectionSnapshot.forEach((doc) => {
     deleteDoc(doc.ref);
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

This is how you delete a document from cloud firestore:

deleteDoc(doc(db, "reference"))

So, the complete code is:

const myCollection = collection(db, 'myCollection');
const mycollectionQuery = query(myCollection, where("field1", "==", "xyz"));
myCollectionSnapshot.forEach((doc) => {
     deleteDoc(doc(db, doc.ref));
});
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