Add a Firestore document using a custom type

Add a Firestore document using a custom type

Documentation pages that include this code sample

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

Code sample


city := City{
	Name:    "Los Angeles",
	Country: "USA",
_, err := client.Collection("cities").Doc("LA").Set(ctx, city)
if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)


City city = new City("Los Angeles", "CA", "USA", false, 3900000L,
    Arrays.asList("west_coast", "socal"));
ApiFuture<WriteResult> future = db.collection("cities").document("LA").set(city);
// block on response if required
System.out.println("Update time : " + future.get().getUpdateTime());


city = City(name=u'Los Angeles', state=u'CA', country=u'USA')

What's next

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