Creating a Firestore client

Creating a Firestore client

Code sample


import (



func createClient(ctx context.Context) *firestore.Client {
	// Sets your Google Cloud Platform project ID.
	projectID := "YOUR_PROJECT_ID"

	client, err := firestore.NewClient(ctx, projectID)
	if err != nil {
		log.Fatalf("Failed to create client: %v", err)
	// Close client when done with
	// defer client.Close()
	return client


Firestore db = FirestoreOptions.getDefaultInstance().getService();


from import firestore

# Project ID is determined by the GCLOUD_PROJECT environment variable
db = firestore.Client()


require "google/cloud/firestore"

firestore = project_id: project_id

puts "Created Cloud Firestore client with given project ID."

What's next

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