Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trouble Deleting in React Native Firebase Firestore

I am trying to delete an object within a firebase firestore database. This was built in react native expo. When I run the code shown below, the console displays "Doc deleted", however, The object I meant to delete still shows in firebase as well as within my applicaton. Any advice would be greatly appreciated.

async function deleteProperty() {
  await firebase.firestore().collection("Properties").get().then((documentSnapshot => {
    documentSnapshot.forEach((doc) => {
      if (doc.data().address == route.params.address) {
        firebase.firestore().collection("Properties").doc().delete().then(() => {
          console.log("Doc deleted")
        }).catch((error) => {
          console.error("Error removing document: ", error)
        })
      }
    })
  }))
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It looks like you have to pass document id to doc() specifically.

firebase.firestore().collection("Properties").doc(doc.id).delete().then(() => {
  console.log("Doc deleted")
}).catch((error) => {
  console.error("Error removing document: ", error)
})

ref: https://firebase.google.com/docs/firestore/manage-data/delete-data#web-version-8

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading