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

150
Vistas
delete collection firebase in v9

can some one explain how can i delete collection in firebase/firestore using v9 using reactjs

firestore()
  .collection('rate')
   .get()
  .then((querySnapshot) => {
  querySnapshot.forEach((doc) => {
    doc.ref.delete();
  });

this code i am using in v8 i need same thing in v9

 const q = query(collection(db, `${udata.id}`));
    const querySnapshot = await getDocs(q);
    querySnapshot.forEach((doc) => {
      // doc.data() is never undefined for query doc snapshots
      console.log(doc.data());
      
    });

already try this but this code only read data this can't allow me to delete so can some one tell me how to do it

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

0

There's a top-level function deleteDoc() to delete documents in using Modular SDK:

import { collection, query, getDocs, deleteDoc } from 'firebase/firestore';

const q = query(collection(db, `${udata.id}`));
const querySnapshot = await getDocs(q);
    
const deleteOps = [];

querySnapshot.forEach((doc) => {
  deleteOps.push(deleteDoc(doc.ref));      
});

Promise.all(deleteOps).then(() => console.log('documents deleted'))
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use deleteDoc(), as documented here.

deleteDoc() takes a document reference, so you'll need to pass the reference from inside the forEach. In the forEach you're receiving a QueryDocumentSnapshot, so you just need to add a

deleteDoc(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