0

How to delete subcolletion of document in firebase?

This is my code where I am getting subcollection "tieredRewards" and company id's which has tiered rewards. I want to delete tieredReward subcollection in every company.

let _query1 = query(collection(db, "companies"));

const companiesSnapshot = await getDocs(_query3);
companiesSnapshot.docs.map(async (doc) => {
  let _query2 = query(
    collection(db, `companies/${doc.id}/tieredRewards`)
  );
  const tieredRewardsSnapShot = await getDocs(_query4);
  if (!tieredRewardsSnapShot.empty) {
    console.log(doc.id);
  }
});

I tried deleteDoc method, but it did not work.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Lucksona
  • 3
  • 1

0 Answers0