// asynchronously delete a documentApiFuture<WriteResult>writeResult=db.collection("cities").document("DC").delete();// ...System.out.println("Update time : "+writeResult.get().getUpdateTime());
import("context""log""cloud.google.com/go/firestore")funcdeleteDoc(ctxcontext.Context,client*firestore.Client)error{_,err:=client.Collection("cities").Doc("DC").Delete(ctx)iferr!=nil{// Handle any errors in an appropriate way, such as returning them.log.Printf("An error has occurred: %s",err)}returnerr}
When you delete a document,Cloud Firestoredoes not automatically
delete the documents within its
subcollections. You can still access the subcollection documents by reference.
For example, you can access the document at path/mycoll/mydoc/mysubcoll/mysubdoceven
if you delete the ancestor document at/mycoll/mydoc.
Non-existent ancestor documentsappear in the console,
but they do not appear in query results and snapshots.
If you want to delete a document and all the documents within its
subcollections, you must do so manually. For more information, seeDelete Collections.
Delete fields
To delete specific fields from a document, use the following language-specificFieldValue.delete()methods
when you update a document:
Web
Use thedeleteField()method:
import{doc,updateDoc,deleteField}from"firebase/firestore";constcityRef=doc(db,'cities','BJ');// Remove the 'capital' field from the documentawaitupdateDoc(cityRef,{capital:deleteField()});
varcityRef=db.collection('cities').doc('BJ');// Remove the 'capital' field from the documentvarremoveCapital=cityRef.update({capital:firebase.firestore.FieldValue.delete()});
valdocRef=db.collection("cities").document("BJ")// Remove the 'capital' field from the documentvalupdates=hashMapOf<String,Any>("capital"toFieldValue.delete(),)docRef.update(updates).addOnCompleteListener{}
DocumentReferencedocRef=db.collection("cities").document("BJ");// Remove the 'capital' field from the documentMap<String,Object>updates=newHashMap<>();updates.put("capital",FieldValue.delete());docRef.update(updates).addOnCompleteListener(newOnCompleteListener<Void>(){// ...// ...
finaldocRef=db.collection("cities").doc("BJ");// Remove the 'capital' field from the documentfinalupdates=<String,dynamic>{"capital":FieldValue.delete(),};docRef.update(updates);
DocumentReferencedocRef=db.collection("cities").document("BJ");Map<String,Object>updates=newHashMap<>();updates.put("capital",FieldValue.delete());// Update and delete the "capital" field in the documentApiFuture<WriteResult>writeResult=docRef.update(updates);System.out.println("Update time : "+writeResult.get());
// Create a document referenceconstcityRef=db.collection('cities').doc('BJ');// Remove the 'capital' field from the documentconstres=awaitcityRef.update({capital:FieldValue.delete()});
import("context""log""cloud.google.com/go/firestore")funcdeleteField(ctxcontext.Context,client*firestore.Client)error{_,err:=client.Collection("cities").Doc("BJ").Update(ctx,[]firestore.Update{{Path:"capital",Value:firestore.Delete,},})iferr!=nil{// Handle any errors in an appropriate way, such as returning them.log.Printf("An error has occurred: %s",err)}// ...returnerr}
To delete an entire collection or subcollection inCloud Firestore,
retrieve (read) all the documents within the collection or subcollection and delete
them. This process incurs both read and delete costs. If you have larger
collections, you may want to delete the documents in smaller batches to avoid
out-of-memory errors. Repeat the process until you've deleted the entire
collection or subcollection.
Deleting a collection requires coordinating an unbounded number of
individual delete requests. If you need to delete entire collections, do so only
from a trusted server environment. While it is possible to delete a collection
from a mobile/web client, doing so has negative security and performance implications.
The snippets below are somewhat simplified and do not deal with error handling,
security, deleting subcollections, or maximizing performance. To learn more
about one recommended approach to deleting collections in production, seeDeleting Collections and Subcollections.
Web
// Deleting collections from a Web client is not recommended.
Swift
Note:This product is not available on watchOS and App Clip targets.
// Deleting collections from an Apple client is not recommended.
Objective-C
Note:This product is not available on watchOS and App Clip targets.
// Deleting collections from an Apple client is not recommended.
Kotlin
// Deleting collections from an Android client is not recommended.
Java
// Deleting collections from an Android client is not recommended.
Dart
Deleting collections from the client is not recommended.
Java
/*** Delete a collection in batches to avoid out-of-memory errors. Batch size may be tuned based on* document size (atmost 1MB) and application requirements.*/voiddeleteCollection(CollectionReferencecollection,intbatchSize){try{// retrieve a small batch of documents to avoid out-of-memory errorsApiFuture<QuerySnapshot>future=collection.limit(batchSize).get();intdeleted=0;// future.get() blocks on document retrievalList<QueryDocumentSnapshot>documents=future.get().getDocuments();for(QueryDocumentSnapshotdocument:documents){document.getReference().delete();++deleted;}if(deleted>=batchSize){// retrieve and delete another batchdeleteCollection(collection,batchSize);}}catch(Exceptione){System.err.println("Error deleting collection : "+e.getMessage());}}
// This is not supported. Delete data using CLI as discussed below.
Node.js
asyncfunctiondeleteCollection(db,collectionPath,batchSize){constcollectionRef=db.collection(collectionPath);constquery=collectionRef.orderBy('__name__').limit(batchSize);returnnewPromise((resolve,reject)=>{deleteQueryBatch(db,query,resolve).catch(reject);});}asyncfunctiondeleteQueryBatch(db,query,resolve){constsnapshot=awaitquery.get();constbatchSize=snapshot.size;if(batchSize===0){// When there are no documents left, we are doneresolve();return;}// Delete documents in a batchconstbatch=db.batch();snapshot.docs.forEach((doc)=>{batch.delete(doc.ref);});awaitbatch.commit();// Recurse on the next process tick, to avoid// exploding the stack.process.nextTick(()=>{deleteQueryBatch(db,query,resolve);});}
import("context""fmt""io""cloud.google.com/go/firestore""google.golang.org/api/iterator")funcdeleteCollection(wio.Writer,projectID,collectionNamestring,batchSizeint)error{// Instantiate a clientctx:=context.Background()client,err:=firestore.NewClient(ctx,projectID)iferr!=nil{returnerr}col:=client.Collection(collectionName)bulkwriter:=client.BulkWriter(ctx)for{// Get a batch of documentsiter:=col.Limit(batchSize).Documents(ctx)numDeleted:=0// Iterate through the documents, adding// a delete operation for each one to the BulkWriter.for{doc,err:=iter.Next()iferr==iterator.Done{break}iferr!=nil{returnerr}bulkwriter.Delete(doc.Ref)numDeleted++}// If there are no documents to delete,// the process is over.ifnumDeleted==0{bulkwriter.End()break}bulkwriter.Flush()}fmt.Fprintf(w,"Deleted collection \"%s\"",collectionName)returnnil}
// This is not supported. Delete data using CLI as discussed below.
C#
privatestaticasyncTaskDeleteCollection(CollectionReferencecollectionReference,intbatchSize){QuerySnapshotsnapshot=awaitcollectionReference.Limit(batchSize).GetSnapshotAsync();IReadOnlyList<DocumentSnapshot>documents=snapshot.Documents;while(documents.Count>0){foreach(DocumentSnapshotdocumentindocuments){Console.WriteLine("Deleting document {0}",document.Id);awaitdocument.Reference.DeleteAsync();}snapshot=awaitcollectionReference.Limit(batchSize).GetSnapshotAsync();documents=snapshot.Documents;}Console.WriteLine("Finished deleting all documents from the collection.");}
A TTL policy designates a given field as the expiration time for documents in a
given collection group. TTL delete operations count towards your document delete
costs.
For more information on error codes and how to resolve latency issues when deleting data check out thetroubleshooting page.
Delete data with Dataflow
Dataflow is a great tool for bulk operations on your Firestore database. The
Firestore connector for Dataflow introductionblog posthas an example of deleting all documents in
a collection group.
Use managed bulk delete
Cloud Firestoresupports bulk deleting one or more collection groups.
For more information, seeBulk delete data.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,[]]