Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!