Ask Your Question
0

What is the method to remove all documents from a firestore collection database?

asked 2022-05-12 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-02-06 03:00:00 +0000

lakamha gravatar image

To delete all documents in a Firestore collection in JavaScript, you can use the following code:

const db = firebase.firestore();
const collectionRef = db.collection('your_collection_name');

collectionRef.get()
  .then(querySnapshot => {
    querySnapshot.forEach(doc => {
      doc.ref.delete();
    });
  })
  .catch(error => {
    console.error("Error deleting collection: ", error);
  });

This code will retrieve all documents in the collection using the get() method, iterate through each document and call the delete() method on the document reference to delete it. Note that this cannot be undone, so use with caution.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-12 11:00:00 +0000

Seen: 7 times

Last updated: Feb 06 '22