Update a Firestore document field

Update a Firestore document 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("DC").Update(ctx, []firestore.Update{
		Path:  "capital",
		Value: true,
if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)


// Update an existing document
DocumentReference docRef = db.collection("cities").document("DC");

// (async) Update one field
ApiFuture<WriteResult> future = docRef.update("capital", true);

// ...
WriteResult result = future.get();
System.out.println("Write result: " + result);


const cityRef = db.collection('cities').doc('DC');

// Set the 'capital' field of the city
const res = await cityRef.update({capital: true});


$cityRef = $db->collection('samples/php/cities')->document('DC');
    ['path' => 'capital', 'value' => true]


city_ref = db.collection(u'cities').document(u'DC')

# Set the capital field
city_ref.update({u'capital': True})


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

What's next

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