firestore: delete data

Delete Data from Cloud Firestore

To delete a document, use the delete() method:

WEB
SWIFT
OBJECTIVE-C
ANDROID
JAVA
PYTHON
MORE
 
   
[[[ self . db collectionWithPath :@ "cities" ] documentWithPath :@ "DC" ]
    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:

WEB
SWIFT
OBJECTIVE-C
ANDROID
JAVA
PYTHON
MORE
 
   
[[[ self . db collectionWithPath :@ "cities" ] documentWithPath :@ "BJ" ] updateData :@{
 
@ "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.

WEB
SWIFT
OBJECTIVE-C
ANDROID
JAVA
PYTHON
MORE
 
   
// Deleting collections from an iOS client is not recommended.
 

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>>

猜你喜欢

转载自blog.csdn.net/leonqiu/article/details/79428092