Delete a Firestore document

Delete a single Firestore document

Code sample

Go

_, err := client.Collection("cities").Doc("DC").Delete(ctx)
if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)
}

Java

// asynchronously delete a document
ApiFuture<WriteResult> writeResult = db.collection("cities").document("DC").delete();
// ...
System.out.println("Update time : " + writeResult.get().getUpdateTime());

Node.js

async function deleteDocs(docRef) {
  const shardsCollectionRef = docRef.collection('shards');
  const shardDocs = await shardsCollectionRef.select('id').get();
  const promises = [];
  shardDocs.forEach(async doc => {
    promises.push(shardsCollectionRef.doc(doc.id).delete());
  });
  return Promise.all(promises);
}

Python

db.collection(u'cities').document(u'DC').delete()

Ruby

city_ref = firestore.doc "#{collection_path}/DC"
city_ref.delete

What's next

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