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

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

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 Report

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 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!