To delete a document, use the delete()
method:
deleteDocumentWithCompletion :^( NSError * _Nullable error ) {
if ( error != nil ) {
NSLog (@ "Error removing document: %@" , error );
} else {
NSLog (@ "Document successfully removed!" );
}
}];
Delete fields
To delete specific fields from a document, use the FieldValue.delete()
method when you update a document:
@ "capital" : [ FIRFieldValue fieldValueForDelete ]
} completion :^( NSError * _Nullable error ) {
if ( error != nil ) {
NSLog (@ "Error updating document: %@" , error );
} else {
NSLog (@ "Document successfully updated" );
}
}];
Delete collections
To delete an entire collection or subcollection in Cloud Firestore, retrieve all the documents within the collection or subcollection and delete them. 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.
Delete data with the Firebase CLI
You can also use the Firebase CLI to delete documents and collections. Use the following command to delete data:
firebase firestore:delete [options] <<path>>