{"id":150,"date":"2019-08-05T19:09:11","date_gmt":"2019-08-05T19:09:11","guid":{"rendered":"https:\/\/kalkus.dev\/?p=150"},"modified":"2023-08-24T23:30:55","modified_gmt":"2023-08-24T23:30:55","slug":"how-to-delete-all-documents-from-a-collection-in-google-cloud-firestore","status":"publish","type":"post","link":"https:\/\/kalkus.dev\/blog\/2019\/08\/05\/how-to-delete-all-documents-from-a-collection-in-google-cloud-firestore\/","title":{"rendered":"How to delete all documents from a collection in Google Cloud Firestore?"},"content":{"rendered":"\n<p>To delete all documents from a Firebase collection in Firestore we need to get the collection, iterate over its elements and delete each one of them:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const db = new Firestore({\n  projectId: \"projectId\",\n  keyFilename: \".\/key.json\"\n});\n\ndb.collection(\"collectionName\")\n  .get()\n  .then(res => {\n    res.forEach(element => {\n      element.ref.delete();\n    });\n  });<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To delete all documents from a Firebase collection in Firestore we need to get the collection, iterate over its elements and delete each one of them:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[202,76],"tags":[33,30,31],"_links":{"self":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts\/150"}],"collection":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":4,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":931,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts\/150\/revisions\/931"}],"wp:attachment":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}