Delete a Firestore field

Delete a Firestore field

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


_, err := client.Collection("cities").Doc("BJ").Update(ctx, []firestore.Update{
		Path:  "capital",
		Value: firestore.Delete,
if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)


DocumentReference docRef = db.collection("cities").document("BJ");
Map<String, Object> updates = new HashMap<>();
updates.put("capital", FieldValue.delete());
// Update and delete the "capital" field in the document
ApiFuture<WriteResult> writeResult = docRef.update(updates);
System.out.println("Update time : " + writeResult.get());


// Get the `FieldValue` object
const FieldValue = admin.firestore.FieldValue;

// Create a document reference
const cityRef = db.collection('cities').doc('BJ');

// Remove the 'capital' field from the document
const res = await cityRef.update({
  capital: FieldValue.delete()


city_ref = db.collection(u'cities').document(u'BJ')
    u'capital': firestore.DELETE_FIELD


city_ref = firestore.doc "#{collection_path}/BJ"
city_ref.update({ capital: firestore.field_delete })

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser